I have a list of objects where each contains an arbitary number of parameters (name,value pairs). Now I want to bind the list of objects to a listview. Each column should represent a parameter (the column header is the name of the parameter) and each row an object with the list of parameter values. How can achive that the columns including its header names are created via databinding based on the parameter names? Note that the number of parameters may differ from object to object so the the column item must be lft blank sometimes.
A:
By parameters you mean properties?
If yes, then this might help:
I think the databinding engine will take the first object and use that as representant for all the others.
So your list will have all columns like properties from the first object.
To achieve your desired result, you should
- Create a dummy object that has all possible properties
- Insert that as first item in the list
That should work... Use reflection, when you use c# :-)
Peter Gfader
2008-12-15 13:12:20
Sorry, no, with Paramters I mean a collection of Paramter objects. A Paramter has a name and a value.
bitbonk
2008-12-15 15:31:02
I guess your final listview should have only 1 row, with all the values from the List<Prm>. Parameter has 2 properties Name and Value. Try this listView.View = Details (so you can actually see column headers) foreach item in List<Prm> do ListView1.Columns.Add(list.Name) --> SubItems.Add(list.Value)
Peter Gfader
2009-03-18 11:56:14