AutoGeneratingColumn with Dynamic PropertiesDictionary<string,object>

Jan 27, 2009 at 8:30 AM
Hello there,

I have a really funny problem.

lets say we have the following constellation:
a list (name mylst) with a lot of object from the type b (name myb1, myb2,myb3...).
the definition of b is this:
b
{
     Dictionary<string,object> Properties {get;}
}
b.Properties is filled dynamicly.

Now I will the following DataGridResult:
lets say
the b1.Properties is filled with Name1:Value1,Name2:Value2,Name3:Value3,Name4:Value4...
and
the b2.Properties is filled with Name10:Value10,Name20:Value20,Name30:Value30,Name40Value40...
and so on...
The diplay should by:
Name1|Name2|Name3|Name4|Name5|Name6|Name7|Name8|Name9|Name10|Name11|Name12....
--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|....
Value1|Value2|Value3|Value4|Value5|Value6|Value7|Value8|Value9|Value10|Value11|Value12|...
           |           |           |           |           |           |           |           |           |Value10|           |           |...

I hope you understand.

a list of hashtables,dictionary or so should displayed in the DataGrid.

Does anyone knows how to do this.

I found this in the WPF Toolkit Sources, but I don't know how to implement it.
        /// <summary>
        /// Helper method which generates columns for a given IItemProperties and adds
        /// them either to a datagrid or to a collection of columns as specified by the flag.
        /// </summary>
        /// <param name="dataGrid"></param>
        /// <param name="iItemProperties"></param>
        /// <param name="columnCollection"></param>
        private static void GenerateColumns(
            IItemProperties iItemProperties,
            DataGrid dataGrid,
            Collection<DataGridColumn> columnCollection)
        {
            Debug.Assert(iItemProperties != null, "iItemProperties should not be null");
            Debug.Assert(dataGrid != null || columnCollection != null, "Both dataGrid and columnCollection cannot not be null at the same time");
            
            ReadOnlyCollection<ItemPropertyInfo> itemProperties = iItemProperties.ItemProperties;

            if (itemProperties != null &&
                itemProperties.Count > 0)
            {
                foreach (ItemPropertyInfo itemProperty in itemProperties)
                {
                    DataGridColumn dataGridColumn = DataGridColumn.CreateDefaultColumn(itemProperty);
....        |