470,619 Members | 1,452 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,619 developers. It's quick & easy.

databinding DataGrid to an IList object [reflection]

Hello,

I am thinking of a general solution to the specific issue and I hope
someone has some more experience on that.

Up to now I use the ListView as the primary control for collections of
items. Unfortunately, the ListView behaves sluggishly with large amounts of
data. That's why I think of using DataGrid instead.

The DataGrid in my application should be databinded to a memory
collection (could be an ArrayList or I could write my own collection).
Nevertheless, as far I as I know, the DataGrid's binding mechanism uses
reflection to ask for public properties in objects that was put into the
collection. That's exactly where the problem is.

Suppose I wish to populate a list where every row contains data from
several different objects. Or only few fields from one object. Or even some
additional data that does not belong to any class. What I need then is some
general mechanism that will allow me to add arbitrary "columns" and fill
columns with arbitrary data (just like you do with the ListView: at first
you add Columns and then add SubItems to each ListViewItem).

Unfortunately, I have no idea how I could mimic such behavior with the
DataGrid bounded to an ArrayList. I thought of a wrapper class that could
contain an array of values (for consecutive columns) but I do not know how
such class could not have a variable number of properties to feed the binder
correctly in various contexts. I do not want to create a separate wrapper
class for any context, of course.

The only solution I could think of is to build a temporary DataTable
with proper columns, copy the data from ArrayList to the DataTable and bind
the DataGrid to the DataTable.

Is there any other possibility that would not require a temporary
DataTable to be created?

Thanks for any suggestions.

Wiktor Zychla
Nov 16 '05 #1
0 1894

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Sarfraz Hooda | last post: by
15 posts views Thread by Rik Brooks | last post: by
1 post views Thread by BB | last post: by
3 posts views Thread by Tom McLaughlin | last post: by
13 posts views Thread by Michael Maes | last post: by
1 post views Thread by suki | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.