Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
165
Deleting the selected item of a comboboxfield
posted

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);
}

}

Parents
  • 34810
    Offline posted

    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

Reply Children