This project has moved and is read-only. For the latest updates, please go here.

Wpf DataGridControl + ComboBox editor in a column - how to clear the value?

Feb 3, 2014 at 3:09 PM
Hi,

I am using Extended WPF Toolkit 2.0.0 and the DataGridControl. One of columns in the grid uses ComboBox as the cell editor (set up using Column.CellEditor). The Column is bound to a navigational property which can be null. The ComboBox's list of items is bound to a collection on ViewModel. It all displays and edits fine.

However, I cannot work out how to clear the value in the cell "properly". The cell can be empty, but the collection of items in the combo does not contain a "blank" value. Once I set the value in the cell, I cannot clear it. I have added a button next to the ComboBox in the cell to clear the property on the item bound to the row in the grid. It kind of works, but I have to save the changes and then refresh the grid to see that there is no value in the cell. I tried refreshing the ComboBox somehow, and the cell itself, calling OnPropertyChange, but no success.

I cannot add "null" to the list of items in the combobox - it fails then.

What is the "proper" way to do it? Clearing the cell's value when the editor is a ComboBox...?
Feb 3, 2014 at 3:48 PM
I found a way of clearing the field and it is a better UX for the user but still I don't think it is "the proper" solution (?). What I do now is: on the button click (the button which is placed together with the combobox in the cell editor) the code behind (not ViewModel) checks the siblings of the sender (VisualTreeHelper.GetParent(...) then iterate through the children of the parent) and finds all combobox objects (there is one only). When a combobox is found, its SelectedItem property is set to null.

It works for me. But I am still interested to see what the "proper" way of doing it would be...