Hi,
I'm following the section "Changing the Default Column and Row Definitions" from the NetAdvantage for WPF documentation.
I'd like to show the data in a double row, with the first 4 fields up and the 5th below :
______________________
Field1 Field2 Field3 Field4
Field5
----------------------------------------
I'm trying to follow the documentation but I'm getting an exception. I'm using this code:
<igDp:XamDataGrid DataSource="{Binding Store}" DockPanel.Dock="Top" AutoFit="True" Name="TheGrid"> <igDp:FieldLayoutSettings AutoArrangeCells="Never" AutoGenerateFields="False" /> <igDp:XamDataGrid.FieldLayouts> <igDp:FieldLayout> <igDp:FieldLayout.Fields> <igDp:Field Name="LoggerName" Row="0" Column="0"/> <igDp:Field Name="Level" Row="0" Column="1"/> <igDp:Field Name="TimeSpan" Row="0" Column="2"/> <igDp:Field Name="Formatted" Row="0" Column="3"/> <igDp:Field Name="Formatted" Row="1" Column="0" ColumnSpan="4" IsExpandable="True"/> </igDp:FieldLayout.Fields> </igDp:FieldLayout> </igDp:XamDataGrid.FieldLayouts> </igDp:XamDataGrid>
But I' getting this exception:
Can't set the DataSource on a DataPresenter that has items added explicitly through the DataItems collection.System.InvalidOperationException: Can't set the DataSource on a DataPresenter that has items added explicitly through the DataItems collection. at Infragistics.Windows.DataPresenter.DataPresenterBase.OnPropertyChanged(DependencyPropertyChangedEventArgs e) at Infragistics.Windows.DataPresenter.XamDataGrid.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
What is the problem? Can't I use databinding?
Cheers.
Probably the problem is the binding of the data and surely in the code-behind file. Please follow this link http://help.infragistics.com/Help/NetAdvantage/WPF/2008.2/CLR3.X/html/WPF_Data_Binding.html and make sure that the grid is bound correctly. If you still have any problems paste me the code-behind file or better the whole solution to take a closer look.
Humm... there is not code behind for that grid, actually I changed the code to this:
<igDp:XamDataGrid DataSource="{Binding Store}" DockPanel.Dock="Top" AutoFit="True"> <igDp:XamDataGrid.FieldLayouts> <igDp:FieldLayout> <igDp:FieldLayout.Fields> <igDp:Field Name="LoggerName" Row="0" Column="0"/> <igDp:Field Name="Level" Row="0" Column="1"/> <igDp:Field Name="TimeSpan" Row="0" Column="2"/> <igDp:Field Name="Formatted" Row="1" Column="0" ColumnSpan="3" IsExpandable="True"/> </igDp:FieldLayout.Fields> </igDp:FieldLayout> </igDp:XamDataGrid.FieldLayouts> </igDp:XamDataGrid>
I've removed the name of the xamDataGrid for be sure nobody is calling it from the code behind, and I've removed this line:
<igDp:FieldLayoutSettings AutoArrangeCells="Never" AutoGenerateFields="False" />
And then is working, there is not exception, but the data is not shown as I want, what could be the problem?
This line should be the problem:
<igDp:XamDataGrid DataSource="{Binding Store}" DockPanel.Dock="Top" AutoFit="True">
If Store is a Static Resource, it look like this for example:
<XmlDataProvider Source="Inventory.xml" x:Key="BooksData" XPath="/Books" />
<igDp:XamDataGrid DataSource="{Binding Source={StaticResource BooksData}, XPath=Book}" DockPanel.Dock="Top" AutoFit="True">
Please attach sample application/project to take a closer look at it.
Thanks.
Store is a property of the code behind class, at the begining we put the class as DataContext of the app, so Store is the name of a property that contains a ObservableCollection<CustomClass>. That binding have to work because at this moment we are using it in a ListBox and runs fine. What we are trying to do is replace the listbox with the xamDataGrid.
The exception "Can't set the DataSource on a DataPresenter that has items added explicitly through the DataItems collection." appears when I use this line:
When I remove that line the data is shown... but no as I want (with the fifth element at the bottom). The only difference is that line, I'm not adding elements via DataItems collection, I only add items to Store, that is the xamDataGrid DataSource.
I hope have been more clear now, sorry for the confusion.