I have a XamDataGrid with a ComboBoxField. The ComboBoxField is populated with a list of custom object having 2 important properties: label, ID.The list of custom objects that populates my XamDataGrid also has label and ID properties. How can I get my comboboxfield to update both the label and ID for the object?
<igDP:ComboBoxField Name="Label" Label="Object Label" ItemsSource="{Binding RelativeSource={RelativeSource Self}, Path=Owner.DataPresenter.DataContext.Nodes, Mode=TwoWay}" DisplayMemberPath="NameLabel" ValuePath="ID" >
Hello Adam,
In order to update the fields of the XamDataGrid based on the selection of the ComboBoxField, what I can suggest you is handling the EditModeEnded event of the XamDataGrid. Inside it the field of the cell that is being edited needs to be checked if it is the same field as the ComboBoxField. After that, the values of the ID and Label fields need to be modified based on the selection. For example, if the ValuePath of the ComboBoxField is the ID, the value for the cell that corresponds to the ID field could be set to it and the value of the cell that corresponds to the Label field should be set in similar manner.
I am attaching a small sample application that demonstrates what I have explained above.
Please test the sample on your side and let me know if you have any questions or concerns.
Regards, Ivan Kitanov
FieldsBasedOnComboBoxField.zip
Ivan,
Thank you for the sample code. I notice in the example that the event only fires once I click out of the ComboBox cell. Is there an event that fires when the comboBox value is selected?
The reason why this is happening is because the event in only triggered once the cell exits edit mode and then the values are changed.
In order to change the data when the user changes the values of the ComboBoxField before exiting edit mode the SelectionChanged event needs to be used. In order to use it an EditorStyle for the ComboBoxFIeld needs to be created and inside it the XamComboEditor should be targeted. Inside the style an EvenSetter should be used for the SelectionChanged event.
Inside the event handler, the active cell needs to be obtained and based on the row index the cell values need to be updated.
Please note that since a custom object is used, for the event argument - e.NewValue, the ToString() method needs to be overridden in order to return the value in a way you would be able to format it for modifying the cells in the same row.
I have modified the sample, in order to demonstrate what I have explained above. You can find it attached below.
Let me know if you have any questions.
FieldsBasedOnComboBoxField_modified.zip
I have implemented the code in your example and it works as expected. Thank you!
I’m glad that you found my suggestion helpful and managed to resolve your issue.
Thank you for choosing Infragistics!