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
Yes, it worked!! Thanks!
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.
Hello Chema,
I have been looking into this and in order to keep, both the FilterDropDown as the FilterCellValuePresenter’s editor and the original values in the data I can suggest registering for the RecordFilterDropDownOpening event where you can change the items’ DisplayText like so:
private void xamDataGrid1_RecordFilterDropDownOpening(object sender, RecordFilterDropDownOpeningEventArgs e)
{
foreach (FilterDropDownItem item in e.DropDownItems)
if (item.IsCellValue)
// ADD DisplayText logic here
item.DisplayText = "region " + item.Value.ToString();
}
Another thing you can try is convert the values from your data into the desired strings before they enter the XamDataGrid’s cells, after which you can use only the string values inside the XamDataGrid and convert them back when changes are made to the data. In order to illustrate this approach I had to modify a few things on the original sample. I have reattached the new version (WpfApplication1_modified.zip)
Please let me know if I can be of any further assistance whatsoever.
Yes, that's right!! We want to show the friendly name of the region to the user but internally we need to work with the id.
So you want the values to be 1,2,3 and at the same time they should appear in the combo as Region 1, Region 2 and Region 3 and also in the filter drop down they should also appear as Region 1, Region 2 and Region 3? Is that right?