I mean i need to bind unbound fields programmatically but i cannot manage to bind to a DataSource of type ObservableCollection<ObservableCollection<String>> sCol :
<igDP:XamDataGrid x:Name="xamDataGrid" DataSource="{Binding sCol}"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:UnboundField Label="Col1" BindingPath="[0]" BindingMode="TwoWay" DataType="sys:String" /> <igDP:UnboundField Label="Col2" BindingPath="[1]" BindingMode="TwoWay" DataType="sys:String"/> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid>
Ouput traces say :
System.Windows.Data Error: 39 : BindingExpression path error: '[' property not found on 'object' ''EnumerableObjectWrapper' (HashCode=14407208)'. BindingExpression:Path=[1]; DataItem='EnumerableObjectWrapper' (HashCode=14407208); target element is 'a' (HashCode=44344604); target property is 'Value' (type 'Object')
I can achive a correct binding through a regular listView though :
<ListView ItemsSource="{Binding sCol}"> <ListView.View> <GridView> <GridViewColumn Header="Col1" DisplayMemberBinding="{Binding [0]}"/> <GridViewColumn Header="Col2" DisplayMemberBinding="{Binding [1]}"/> </GridView> </ListView.View> </ListView>
It seems that the grid DataSource property does not behave like the list ItemsSource property.
What am I missing ?
Cheers.
Hi Alan,
Please suggest the changes in above code for Hierarchial Data with 2 layers.
Thanks,
Shakti
Prasanna,
The example that I provided earlier in this thread is the only existing example that I have. You would have to modify this so that the header and row collections could be exposed as properties on a user control and then when the properties are set update the XamDataGrid appropriately.
Even if this is only going to be used in one place in your application it would still make sense to use the XamPivotGrid since the control already provides the functionality that you are looking for.
Let me know if you have any questions with this matter.
Hi Alan,Thanks for your reply. But this is a one-off requirement so I am looking for a XamDataGrid solution. Can you please elaborate on how to expose a property for the Headers and then update FieldLayout accordingly. If you have a sample or already posted solution please let me know.Regards,Prasanna
Hello,
I would recommend using the XamPivotGrid rather than the XamDataGrid which could display the data in this way when binding to a flat data source. You can find more details on the XamPivotGrid here:
http://ko.infragistics.com/dotnet/netadvantage/wpf/data-visualization/xam-pivot-grid.aspx#Overview
Can you give me a sample with this approach.
If not can you look at my requirement below and suggest some MVVM approach. There are two types of fields a user can select namely "Periods" and "Abbrev". Upon selecting the two sets of fields, it results in a Flat Grid (see Figure 1 below). I need to convert this flat grid into another grid as shown in Figure 2 below.
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4
Name
Period
Abbrev
Value
abc
CY
Unadj
10
Adj
17
Final
21
PY
1000
2000
Fig 1
77
xyz
45
50
23
3000
4000
88
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4
Unadj CY
Adj CY
Final CY
Final PY
Fig 2