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