We have a class called TestData which contains a string called Header and a list of doubles called Data. We then add several of these TestData objects to an ObservableCollection<TestData> called UberData. As new data becomes available at run time, we either add items to the Data list of an existing TestData object in the UberData collection , or we add an entirely new TestData object to the collection. For example we might have an ObservableCollection<TestData> that contains TestData.Header = “Channel1” and TestData.Header=”Channel2”, etc.
We would like to databind the first column of the grid to the Data list for channel 1, inside the UberData collection, and the second column of the grid to the Data list object for channel 2 etc. In the binding we would like to bind the grids column 1 header to TestData.Header and the data for the grid column to TestData.Data.
Is this possible? We have failed to do this with the Microsoft WPF Grid. The general problem has been that we don't know how many collections will be inside the Uber collection as it is dynamic i.e. we don't know how many at design time.
The MS Grid control has this behaviour: A data row is created for each object in the collection, and a column is created for each property. The values of the cells in each data row correspond to the property value of each object.
Our data is column centric. We need a column for each object in the collection. Another way to put this is I have 3 arrays of doubles how do I get array 1 to show in column 1 and array 2 to show in column 2 etc.
Thanks
Hello John,
Thank you for your post. I have been looking into it and I can suggest you set the XamDataGrid’s ViewSettings’ Orientation to Horizontal like this:
<igDP:XamDataGrid.ViewSettings> <igDP:GridViewSettings Orientation="Horizontal"/> </igDP:XamDataGrid.ViewSettings>
Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
No this is not quite what we want. Let me start with something more simpler.
If I have 3 arrays of doubles and I want array 1 to be in column 1 and array 2 in column 2 etc how do I do it.
If you could send me an isolated sample project, with a data that has a structure like your original one and screenshots of the desired result, I will be able to think of a possible solution for you.
Stefan,
Thanks for your interest. I have attached a project we have been experimenting with.
We have been using collections because we wanted the grid to update when any new data was appeanded to it.
As you can see in this project we have created our own grid which shows the results we would like to see.
John
I have tried the code you have provided and I can say that this behavior is expected since adding UnboundFields is time and CPU consuming operation and in order to achieve the look and functionality yo uwant this seems to be the best approach, but if I think of another faster one I will let you know.
I ran your code and it works great.
The only issue I now have is our data could be up to 1,000,000 values. I ran the test application and added 10,000, just as a test, to this loop shown below and the application takes several minutes to launch.
void xamDataGrid1_FieldLayoutInitialized(.........
{
for (int i = 0; i < ((this.DataContext as ViewModel).TestData.FirstOrDefault() as Model ).Data.Count + 10000; i++)
e.FieldLayout.Fields.Add(new UnboundField() { BindingPath = new PropertyPath("Data[" + i + "]", null) });
}
I have been looking into your post and I modified the sample project following your scenario and everything seems to work ok on my side. If the sample doesn’t satisfies all your needs feel free to modify it, so it reproduces your behavior and send it back to me for further investigation.
Magic, thanks. I am still trying to understand the code in the FieldLayoutInitialized event.
If we add some data to the existing collections inside TestData it doesn't show up. What do I need to do to get the existing data with the new values to show.
To simulate this we had the button which called the button1_click event code.
I have been looking into the simple you have sent me and I modified it, so now it works as you want. Basically I set the Orientation of the XamDataGrid to Horizontal and handled the FieldLayoutInitialized event and in its handler I add UnboundFields for the Data Model Items.
Hope this helps you.