DataGrid and ObservableCollection<ObservableCollection<>>

Jul 7, 2010 at 9:29 AM

Hi all,
(C# 2010) I have to display and edit data on a Datagrid.
DataGrid's datasource is an ObservableCollection<Class1>.
Class1 has 4 properties: 3 are strings & the fourth is a ObservableCollection<Class2>. Class2 has three properties: a double, a string and a boolean.

In the DataGrid I need to create 3 columns for the three Class1's properties, and many other columns as the number of items in the Class2 collection.
this code works

for (int i = 0; i < numberofcolumnstobecreated; i++)
   PropertyPath ppath0 = new PropertyPath(".Class2[" + i.ToString() + "].Class2doubleproperty");

   Binding bb0 = new Binding();
   bb0.Path = ppath0;
   DataGridTextColumn col0 = new DataGridTextColumn();
   col0.Header = i.ToString();
   col0.Binding = bb0;

but I need to create columns that, based on Class2.TheBooleanProperty display an image (which path is stored in Class2.TheStringProp) or a textboxcolumn binded to Class2.TheDoubleProperty.

Could someone point me in the right direction, or give sample? I'm trying to use templatedcolumns, with templateselectors with no succes...


Jul 12, 2010 at 5:56 PM
Hi, I tried to reproduce the case, but I couldn't comprehend the case It seems complicated when you summarize the case in this way? Could you please use realistic words instead of class1&2 and more clear sentences?