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 Petar,
What I try to achieve is to see in the filter of the Region the name of the region ("region1" for instance) instead of its id ("1").
The filter options should be the names of the regions and not their id's.
Thanks.
Hi Chema,
Excuse me for the late reply. I have been looking into this and frankly I am having a hard time understanding what the overall goal is here. Would you please summarize what the end result should be in the sample application you have reattached.
Thanks in advance. Looking forward to hearing from you.
I tried your solution and unfortunately it does not work yet. Our RegionFI is a foreign key to the table Region and therefore of type int. And in this case, the data is not properly presented. If we change the ValuePath to ID (as we have in our project), the data is good, but not the filter.
I send you the sample project back with the tiny modification.
Thanks!
Thank for the update, I’ll be looking forward to hearing from you.
Hi!
Sorry that I didn't answer sooner but I've been away two weeks. I will take a look at it this week and let you know.
Thanks a lot!