laffo16
2014-04-26T01:36:14Z
Hi,

What is the cleanest / fastest approach to getting IEnumerable<CustomType> data into iGrid, including column headers and with the least amount of boxing.
Any example code would be much appreciated!

Thanks!
Igor/10Tec
2014-04-26T06:35:27Z
In iGrid, we have the FillWithData method used to populate it from a data source of one of the following types: DataTable, DataView, IDbCommand, or IDataReader. If you can convert your data into one of these objects, then you can use FillWithData.

***

However, from time to time I hear about the need to support generic collections in FillWithData, and your case is one of them. We can discuss how such an algorithm should work, and if it is an enough universal solution, I could incorporate it into the future releases of iGrid.
laffo16
2014-04-26T15:04:06Z
Hi IgorK,

I have been playing around with getting IEnumerable<Type> to iGrid, see code below FillWithDataIEnumerable(), but there is some boxing involved. I've also had a look around for a IEnumerable to DataTable extension and included my findings below under ToDataTable(). Any ideas for improving FillWithDataIEnumerable()? or do you think converting the results to a DataTable would be best.

ToDataTable ref: here 

example code: here 

btw: forums C# Code syntax highlighting breaks on square bracket array[0] values
Igor/10Tec
2014-04-28T15:20:23Z
Originally Posted by: laffo16 

see code below FillWithDataIEnumerable(), but there is some boxing involved.



Do you mean the boxing in the following code snippet

引用:

var property = (PropertyInfo)col.Tag;
var objValue = property.GetValue(element, null);
row.Cells[i].Value = objValue;



, when we retrieve the field value as Object?

You should not worry about that because the iGrid cell value has the Object type too (to have the ability to store any type of data in its cells). In fact, even if you have a value in its native type (integer, string, date, etc), it is boxed when it is stored in iGrid.

Originally Posted by: laffo16 

I've also had a look around for a IEnumerable to DataTable extension and included my findings below under ToDataTable(). Any ideas for improving FillWithDataIEnumerable()? or do you think converting the results to a DataTable would be best.



You cannot avoid boxing in this scenario too as the values from the <CustomType> properties in their native format are boxed when they are placed into the DataTable. After that they come into iGrid as boxed Object values, the question is only the step when they are boxed.

***

Why are you worrying about boxing? The current iGrid ideology works well even if you have a grid with 500000 rows and 20 columns. In fact, it works like the standard DataTable object, with DataRows which also store field values as object values.
Igor/10Tec
2014-04-28T15:47:22Z
Originally Posted by: laffo16 

btw: forums C# Code syntax highlighting breaks on square bracket array[0] values



Thank you for reporting this! Let's start the discussion of this problem in the Forum Issues section:

http://10tec.com/Forum/y...ket-array-0--values.aspx 
laffo16
2014-04-29T00:28:31Z
To be honest i wasn't sure whether or not there was a boxing issue, I'm just putting bits and pieces together as i go. After my first FillWithDataIEnumerable() attempt I began wondering if there there was a better approach instead of putting PropertyInfo in the Tag and then using property.GetValue(), an alternative approach was already in front of me in the ToDataTable() code using the ReflectionUtility class.

source: here 

This turns out to be about 1/3 quicker then storing PropertyInfo in tag and calling .GetValue().

For anyone else using this, you may also want to call BeginUpdate() before and EndUpdate() after FillWithDataIEnumerable().

Thanks for your help IgorK,

Just for the record, there is no difference in speed between doing this or converting IEnumerable<T> to a DataTable and using FillWithData().
Btw, I haven't test this code with nullable<Types>.