I am binding a dictionary (int, string) to a xamcombobox as follows
<igDP:UnboundField Width="70" ToolTip="Assigned Entity" Tag="EntityString" Label="Assigned Entity" BindingPath="EntityString" BindingMode="TwoWay"> <igDP:UnboundField.Settings> <igDP:FieldSettings CellValuePresenterStyle="{StaticResource LegalEntityDropdownCellStyle}" EditorType="{x:Type igEditors:XamComboEditor}"/> </igDP:UnboundField.Settings> </igDP:UnboundField>
where the CellValuePresenterStyle is defined as
<Style x:Key="LegalEntityDropdownCellStyle" TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:CellValuePresenter}"> <igEditors:XamComboEditor SelectedItem="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Value, Mode=TwoWay}" ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}, Path=DataContext.LegalEntityNames}" DisplayMemberPath="Value" ValuePath="Key"/> </ControlTemplate> </Setter.Value> </Setter> </Style>
I find that the value of the items in the combobox is in format "[key, value]" so I bind the field to a similarly formatted string. At the moment, the selectedItem in the combo box is not set. Any idea how to achieve that?
Changed BindingPath="EntityString"
EntityString to be a KeyValuePair and the selected item sets correctly. However if I change the selected item it gives me a conversion error. Added a converter to convert the "[key,value]" string to an actual KeyValue pair but no luck.
Anyone????
Added converter to field
<igDP:UnboundField Width="70" ToolTip="Assigned Entity" Tag="EntityString" Label="Assigned Entity" BindingPath="EntityString" Converter="{StaticResource legalEntityNameConverter}" BindingMode="TwoWay">
<igDP:UnboundField.Settings>
<igDP:FieldSettings AllowEdit="True" CellValuePresenterStyle="{StaticResource LegalEntityDropdownCellStyle}" EditorType="{x:Type igEditors:XamComboEditor}" />
Still getting the conversion error on selecting the a new value. Apparently the converter kicks in after the value is bound to the underlying field.
Hello,
I have created a sample project for you following your scenario and everything seems to work ok on my side. If the sample doesn’t satisfies all your needs feel free to modify it, so it reproduces your behavior and send it back to me for further investigation.
Looking forward for your reply.
Thanks a ton Stefan. Its working now.
Really appreciate your help.
Iam able to set the selected item in the XamComboEditor but have another problem now...
Basically I have 2 ObservableCollections (say A1 and A2). public class A1{ public virtual int Individual_ID { get; set; } public virtual string Tel_Number { get; set; } public virtual string Tel_Code { get; set; } public virtual string Dial_Number { get; set; } public virtual string Extension { get; set; }}public class A2{ public virtual string Tel_Code { get; set; } //ValuePath public virtual string Tel_Desc { get; set; } //DisplayMemberPath}A1 is bound to the XamDataGrid and A2 is bound to the XamComboEditor. The XamDataGrid & XamComboEditor are populated fine with their respective datasources.Now, when i select another item from the XamComboEditor, the value is not getting updated in the ObservableCollection A1. When i check for the same in the ObservableCollection A2 the first item of the XamComboEditor is being set as the value.
Requirement: We are using EF and I need to save A1 to database. Please help.
I have modified the sample I sent you before, so now you can see that the Data is updated when the ComboBox’ SelectedItem changes.
Hope this helps you.
Hi Stefan
Your sample works like a charm.
But I still have a problem. As we are using MVVM pattern, I dont want to have the "XCEselectedItemChanged" event in the xaml.cs file. Is there any way we can notify the "SelectedItemChanged" to the view model?
I am absolutely new to WPF and have no clue how to achieve this.
Any help is highly appreciated.
Hello Vikram,
I have modified teh sample I sent you before, so now all the code is in separate classes. Please let me know if this heslp you or you need further assistance on this maatter.
Looking forward for you.
Hi Stefan,
Your solution still has the "SelectedItemChanged" code in the "App.xaml.cs" file. Is there anyway of doing this without having this event at all and notifying the ViewModel about the selected item change in the XamComboEditor?
As we are using the MVVM pattern, we are not supposed to have any code in the .cs page.
Please help..
Regards,
Vikram
I have modified the sample I sent you before, so now it has the functionality you want. Basically I moved the Style and the event handler for the XamComboEditor in App.xaml and App.xaml.cs files.