Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
135
Cannot bind XamDataGrid with observablecollection with existing items
posted

I use MVVM pattern and the viewmodel populates anb observablecollecction called GastosInforme defined: 

  public ObservableCollection<GastoInformeWrapper> GastosInforme { get; }

the xamdatagrid is defined as follows:

<igDP:XamDataGrid Name="grid"
DataSource="{Binding GastosInforme}">
<igDP:FieldLayoutSettings AutoGenerateFields="False"/>
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout>

<igDP:FieldLayout.Fields>
<igDP:TextField Name="NumFac" Label="Factura" Width="Auto" />

<igDP:TextField Name="NombreProveedor" Label="Proveedor" Width="100"/>

<igDP:TextField Name="Descripcion" Label="Descripción" Width="250"/>

<igDP:ComboBoxField Name="DepartamentoId" Label="Departamento" Width="100"
ItemsSource="{Binding DataContext.Departamentos, RelativeSource={RelativeSource AncestorType=igDP:XamDataGrid}}"
DisplayMemberPath="DisplayMember"
ValuePath="Id"/>

<igDP:ComboBoxField Name="PartidaId" Label="Partida" Width="100"
ItemsSource="{Binding DataContext.Partidas, RelativeSource={RelativeSource AncestorType=igDP:XamDataGrid}}"
DisplayMemberPath="DisplayMember"
ValuePath="Id"/>

<igDP:DateTimeField Name="FechaPago" Label="Fecha de pago" Width="Auto"/>

<igDP:TextField Name="Importe" Label="Monto" Width="120"/>

<igDP:ComboBoxField Name="EstatusGastoId" Label="Estatus" Width="100"
ItemsSource="{Binding DataContext.Estatus, RelativeSource={RelativeSource AncestorType=igDP:XamDataGrid}}"
DisplayMemberPath="DisplayMember"
ValuePath="Id"/>
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>

after the loading is completed I get this error: 

Can't set the DataSource on a DataPresenter that has items added explicitly through the DataItems collection.

Please help, this is a simple thing I cannot see the problem after reviewing the forum and docs.

Best regards,

Enrique Santa Cruz

Parents
  • 2860
    Verified Answer
    Offline posted

    Hi Enrique,

    Thank you for posting to Infragistics Community!

    I believe the error is caused by the igDP:FieldLayoutSettings not being wrapped within the required <igDP:XamDataGrid.FieldLayoutSettings> tags:

    <igDP:XamDataGrid.FieldLayoutSettings>
         <igDP:FieldLayoutSettings AutoGenerateFields="False" />
     </igDP:XamDataGrid.FieldLayoutSettings>

    More details along with code snippets can be found in our documentation, such as the “Specifying Settings for FieldLayouts” topic.

    Please, try this on your side and let me know if it resolves the error. Below you can also find attached a small sample demonstrating a bound grid for reference.

    Best regards,
    Bozhidara Pachilova
    Software Developer

    1881.XDGData.zip

Reply Children
No Data