Hello,
Normal 0 21 false false false DE X-NONE X-NONE
Let me explain my issue.
We have a XamDataGrid which its DataSource is a binding to an ObservableCollection within a ViewModel (Farms). One of the fields of the XamDataGrid is an extended XamComboEditor with the properties SelectedValue and SelectedValuePath.
We bind the ComboEditor field using the ItemsSource property to another ObservableCollection (RegionItems) of another ViewModel. In this field our DisplayMemberPath is a name (Region) and the SelectedValuePath and ValuePath are the ID of the Region.
All of these works fine until we try to filter the result through the Region in the UI. In this case the ID is shown and not the name of the Region. Something similar happens when we generate a report. In the report it is shown the ID instead of the name of the element.
We don’t know the reason why this is happening. We’ve thought, we should use a ComboBoxItemsProvider for the XamComboEditor, but the same binding fails if we use the provider.
Here is some of the currently code:
<xamDataGridExt:XamDataGridMvvm Grid.Row="1" DataSource="{Binding Farms}" ActiveDataItem="{Binding SelectedItem}" Name="XamDataGridMvvm">
<igDP:Field Name="RegionFI" Label="Region"> <igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igEditorsExt:XamComboEditorExt}"> <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditorsExt:XamComboEditorExt}"> <Setter Property="DisplayMemberPath" Value="Region"/> <Setter Property="ItemsSource" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type igDP:DataRecordPresenter}}, Path=DataRecord.DataItem.RegionItems, Mode=OneWay}"/> <Setter Property="SelectedValuePath" Value="ID"/> <Setter Property="SelectedValue" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type igDP:DataRecordPresenter}}, Path=DataRecord.DataItem.RegionFI}"/> <Setter Property="ValuePath" Value="ID"/> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings></igDP:Field>
This new code doesn't work:
<igDP:XamDataGrid.Resources> <igEditors:ComboBoxItemsProvider x:Key="RegionsItemsProvider" DisplayMemberPath="Region" ValuePath="ID" ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type igDP:DataRecordPresenter}}, Path=DataRecord.DataItem.RegionItems, Mode=OneWay}" /> <Style x:Key="RegionFieldStyle" TargetType="{x:Type igEditors:XamComboEditor}"> <Setter Property="ItemsProvider" Value="{StaticResource RegionsItemsProvider}" /> </Style> </igDP:XamDataGrid.Resources>
<igDP:Field Name="RegionFI" Label="Region}"> <igDP:Field.Settings> <igDP:FieldSettings EditorType="{x:Type igEditorsExt:XamComboEditorExt }" > <igDP:FieldSettings.EditorStyle> <Style TargetType="{x:Type igEditorsExt:XamComboEditorExt}"> <Setter Property="ItemsProvider" Value="{DynamicResource RegionsItemsProvider}" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
If we execute this code we become the following in the Immediate Window, although the ItemsSource in both cases is the same:
System.Windows.Data Error: 4: Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Infragistics.Windows.DataPresenter.DataRecordPresenter', AncestorLevel='1''. BindingExpression:Path=DataRecord.DataItem.RegionItems; DataItem=null; target element is 'ComboBoxItemsProvider' (HashCode=64360188); target property is 'ItemsSource' (type 'IEnumerable')
We would be grateful for any help.
Thanks,
Chema
Hi Chema,
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
If this is what you were looking for please verify the answer so it helps other users as well.
Yes, it worked!! Thanks!