Good Morning
So I have the following XamDataGrid
As you can see, when I selected title 1 in the first row, it was removed from the list in the second row. However, if I change the selection in the first row to title 3 for example, title 1 won't reappear in the second row, instead both titles 1 and 3 will be removed. How can I solve this problem, I only want the currently selected value to be removed.
Here is my backend code:
private void XamDataGrid_DataValueChanged(object sender, DataValueChangedEventArgs e) {
SampleData sd = e.Record.DataItem as SampleData;
ViewModel vm = new ViewModel();
if (e.Field.Name == "Combo1") { string s = sd.Combo1; if (s != null) vm.AccountTitle_Combo.Remove(s); }
}
Hello Nour,
I have been investigating into the behavior you are looking to achieve, and I am under the impression that you are looking to have your XamComboEditor editors be dependent on what is selected in the first row. If this is not the case, please let me know as the following is based on that impression:
I am attaching a sample project that demonstrates how you can do this in an MVVM way. I used a Behavior<XamDataGrid> to handle the DataValueChanged event. Please note that you need to opt into this event by setting the FieldSettings.DataValueChangedNotificationsActive property to true.
In the ViewModel, I have two collections that start out the same, but one is bound to the first record in the XamDataGrid and the other is bound to all of the others. This is done using a DataTrigger in a Style for XamComboEditor in the ComboBoxField. There is also an object in the ViewModel that caches the previously selected first combo-box object both in Value and the Index of the item.
In the DataValueChanged event, I get the ViewModel that is the data context of the XamDataGrid so that I can access these collections and the cached object. In the event, I check the Field.Name and Record.Index from the event arguments, and then from that record get the new value of the cell. The newly selected combo item is then removed from the "dependent" combo values collection, the old one is re-added at the index it was originally, and the newly selected value is cached.
I hope this helps you. Please let me know if you have any other questions or concerns on this matter.
1321.XDGComboDependentValues.zip
Thank you for your reply. What you sent me is not my request. what I need is for the selected value in the combobox field in the first row to be removed from the same combobox field in the second row. But suppose the selection rechanged in the first row, then this change should also be applied in the second row.
My apologies, it appears that I have two sample projects on my machine that have very similar names. I am attaching the real sample project here.
Please let me know if you have any other questions or concerns on this matter.
XDGDependentComboCase.zip
this is the screenshot of the project you sent me. As you can see, I selected A0 in the first row, but it still remains as a choice in the second row. what I need is when I select A0 in the first row, the second row should start from A1, but suppose I later changed the first row to A3, A0 would reappear in row 2 but A3 now will be removed.
Thank you for your update on this matter, although I’m a little unsure on how the sample project I sent you does not achieve your requirement in this case though?
If the issue here is in the case of the “N/A” item – this essentially means that nothing will be removed – acting as a sort of “null selection” but if you select any of the lettered items in the first row, you will see that they are removed from every other row. Then, if you change that selection, it will come back and the new selection will be removed, assuming that the selection is not “N/A” in which case nothing will be removed from the other combo editors.
If this still does not comply with your requirement, then would it be possible for you to please clarify your requirement? Please let me know if you have any other questions or concerns on this matter.