Hello,
I have a XamGrid with 2 ComboBoxColumns. I set their ItemSource in my c# codebehind. I need to allow the ComboBoxes in the columns to cascade, meaning when I select a value in ComboBox1 then ComboBox2 is populated based on what was selected in ComboBox1. This would be similar to a State and City comboboxcolumn scenario.
Select State in ComboBox1 which fires an event to populate ComboBox2 with only the cities that are contained in that state.
How can I do this?
Hello Gary,
In order to achieve your requirement in this case, I would recommend having an underlying collection property on your underlying data item that will represent your dependent combo’s ItemsSource. Doing this, you can assign that ItemsSource in your ViewModel in the setter of the dependent property.
In your XAML, you can define an EditorStyle which will take a Style targeting ComboBox in the case of the ComboBoxColumn. The data context of the ComboBox will be your underlying data item, and you can then bind its ItemsSource to the underlying collection property mentioned above.
I am attaching a sample project to demonstrate the above. I hope it helps you.
It is worth noting that we generally recommend that you use the XamDataGrid control instead of the XamGrid control at this point. The XamGrid control is being planned for retirement over the next few years and will not be receiving any new features. We will continue to provide support and critical bug fixes to the XamGrid during this time, though.
Please let me know if you have any other questions or concerns on this matter.
XamGridCascadingCombo.zip
Thanks for the info.
I have changed my approach and will be using a XamDataGrid for this application. Is the process the same for implementing a cascading set of combo boxes?
Thank you for your update. The process is very similar for the XamDataGrid, yes.
The biggest difference in this case is that the EditorStyle will be for XamComboEditor, and the ItemsSource binding to {Binding DataItem.Cities} as the data context of the editor will not be the data item automatically – it will be the row/record.
I have updated the sample project I originally sent you to add a XamDataGrid as well as the XamGrid so you can see the differences.
0815.XamGridCascadingCombo.zip
This is great. Thanks for putting together the sample solutions.