When I define a xamDataGrid with ColumnsDefinitions in the DataPresenter, or even If I define FieldSettings, when I set the DataSource property (in code behind) I get the error "Can't set the DataSource on a DataPresenter that has items added explicitly through the DataItems collection".
How can I bind my table to the xamDataGrid in this case ?
Thanks in advance
Marcos
Jo,
Thanks a lot for your help.
Marcos,
The problem is that you have a XamDataPresenter inside the XamDataGrid. Tjis is what it should look like instead:
<inf:XamDataGrid DockPanel.Dock="Top" Name="xdgAffVersions" Width="365" AutoFit="True" GroupByAreaLocation="None" Background="LightGoldenrodYellow" >
<inf:XamDataGrid.FieldLayoutSettings> <inf:FieldLayoutSettings AutoGenerateFields="False" /> </inf:XamDataGrid.FieldLayoutSettings> <inf:XamDataGrid.FieldLayoutSettings> <inf:FieldLayoutSettings> <inf:FieldLayoutSettings.DataRecordCellAreaGridTemplate> <ItemsPanelTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="20"/> <ColumnDefinition Width="20"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> </Grid> </ItemsPanelTemplate> </inf:FieldLayoutSettings.DataRecordCellAreaGridTemplate> </inf:FieldLayoutSettings> </inf:XamDataGrid.FieldLayoutSettings> <inf:XamDataGrid.FieldLayouts> <inf:FieldLayout> <inf:FieldLayout.Fields> <inf:Field Name="CSID" Visibility="Collapsed" /> <inf:Field Name="Version" Label="Version"> <inf:Field.Settings> <inf:FieldSettings CellWidth="20" LabelWidth="20" /> </inf:Field.Settings> </inf:Field> <inf:Field Name="DateCreation" Label="Crée le" > <inf:Field.Settings > <inf:FieldSettings CellWidth="40" LabelWidth="40" > <inf:FieldSettings.EditorStyle> <Style TargetType="{x:Type ige:ValueEditor}" > <Setter Property="Format" Value="dd/mm/yyyy"/> </Style> </inf:FieldSettings.EditorStyle> </inf:FieldSettings> </inf:Field.Settings> </inf:Field> <inf:Field Name="CSStatusID" Label="Status" /> </inf:FieldLayout.Fields> </inf:FieldLayout> </inf:XamDataGrid.FieldLayouts></inf:XamDataGrid>
Hi Joe, thanks for your help What I'm trying to do is to set the columns widht, and to indicate what column can grow if the user maximize the window. I tried to set the fields widht but it doesn't work. I saw in the forum that the only way is to assign the widht in the columnsdefinitios. Here is my xaml: <inf:XamDataGrid DockPanel.Dock="Top" Name="xdgAffVersions" Width="365" AutoFit="True" GroupByAreaLocation="None" Background="LightGoldenrodYellow" > <inf:XamDataGrid.FieldLayoutSettings> <inf:FieldLayoutSettings AutoGenerateFields="False" /> </inf:XamDataGrid.FieldLayoutSettings> <inf:XamDataPresenter x:Name="DP1" AutoFit="True" > <inf:XamDataPresenter.FieldLayoutSettings> <inf:FieldLayoutSettings> <inf:FieldLayoutSettings.DataRecordCellAreaGridTemplate> <ItemsPanelTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="20"/> <ColumnDefinition Width="20"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> </Grid> </ItemsPanelTemplate> </inf:FieldLayoutSettings.DataRecordCellAreaGridTemplate> </inf:FieldLayoutSettings> </inf:XamDataPresenter.FieldLayoutSettings> </inf:XamDataPresenter> <inf:XamDataGrid.FieldLayouts> <inf:FieldLayout> <inf:FieldLayout.Fields> <inf:Field Name="CSID" Visibility="Collapsed" /> <inf:Field Name="Version" Label="Version"> <inf:Field.Settings> <inf:FieldSettings CellWidth="20" LabelWidth="20" /> </inf:Field.Settings> </inf:Field> <inf:Field Name="DateCreation" Label="Crée le" > <inf:Field.Settings > <inf:FieldSettings CellWidth="40" LabelWidth="40" > <inf:FieldSettings.EditorStyle> <Style TargetType="{x:Type ige:ValueEditor}" > <Setter Property="Format" Value="dd/mm/yyyy"/> </Style> </inf:FieldSettings.EditorStyle> </inf:FieldSettings> </inf:Field.Settings> </inf:Field> <inf:Field Name="CSStatusID" Label="Status" /> </inf:FieldLayout.Fields> </inf:FieldLayout> </inf:XamDataGrid.FieldLayouts></inf:XamDataGrid> Thanks in advance, Marcos
Hi Joe, thanks for your help
What I'm trying to do is to set the columns widht, and to indicate what column can grow if the user maximize the window. I tried to set the fields widht but it doesn't work. I saw in the forum that the only way is to assign the widht in the columnsdefinitios. Here is my xaml:
<inf:XamDataGrid.FieldLayoutSettings> <inf:FieldLayoutSettings AutoGenerateFields="False" /> </inf:XamDataGrid.FieldLayoutSettings> <inf:XamDataPresenter x:Name="DP1" AutoFit="True" > <inf:XamDataPresenter.FieldLayoutSettings> <inf:FieldLayoutSettings> <inf:FieldLayoutSettings.DataRecordCellAreaGridTemplate> <ItemsPanelTemplate> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="20"/> <ColumnDefinition Width="20"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> </Grid> </ItemsPanelTemplate> </inf:FieldLayoutSettings.DataRecordCellAreaGridTemplate> </inf:FieldLayoutSettings> </inf:XamDataPresenter.FieldLayoutSettings> </inf:XamDataPresenter> <inf:XamDataGrid.FieldLayouts> <inf:FieldLayout> <inf:FieldLayout.Fields> <inf:Field Name="CSID" Visibility="Collapsed" /> <inf:Field Name="Version" Label="Version"> <inf:Field.Settings> <inf:FieldSettings CellWidth="20" LabelWidth="20" /> </inf:Field.Settings> </inf:Field> <inf:Field Name="DateCreation" Label="Crée le" > <inf:Field.Settings > <inf:FieldSettings CellWidth="40" LabelWidth="40" > <inf:FieldSettings.EditorStyle> <Style TargetType="{x:Type ige:ValueEditor}" > <Setter Property="Format" Value="dd/mm/yyyy"/> </Style> </inf:FieldSettings.EditorStyle> </inf:FieldSettings> </inf:Field.Settings> </inf:Field> <inf:Field Name="CSStatusID" Label="Status" /> </inf:FieldLayout.Fields> </inf:FieldLayout> </inf:XamDataGrid.FieldLayouts></inf:XamDataGrid>
Thanks in advance,
Hi Marcos,
It sounds like you have nested tags for other elements inside the xamDataGrid. In this case the xamDatagrid thinks that they are data and adds them to an internal data list, in the same way that a ListBox would. In this case we do the same thing that a Listbox would and prevent binding to a DataSource. The 2 methods of populating the XamDataGrid with data are mutually exclusive. This is by design.
If you can supply a sample of your xaml I can try to see what is wrong.