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
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.
Hi Chema,
Excuse me for the late reply, I have been looking into this and have made a sample project (WpfApplicaiton1.zip) that seems to work, when both DisplayMemberPath and ValuePath are set to region.
Please look let me know if I can be of any further assistance on the matter.
Yes, I have tried but it does not work either. The moment I set ValuePath to Region it shows the ID, and if I set the ValuePath to ID, it shows the Region.
Have you tried setting both ValuePath and DisplayMemeberPath properties to Region?
Hi Petar,
Thank you for your answer!!
In order to achieve it we just changed our property to return the name and not the ID and appartently it works. We changed the ValuePath to "Region" but then the ID it's shown in the DataGrid.