Unselect item in Combobox in DataGrid

Feb 2, 2009 at 7:59 PM
Edited Feb 2, 2009 at 7:59 PM
If a user is using a comboboxcolumntype and they select and item and then change their mind, how can I put it back to an unselected state? 
Feb 4, 2009 at 12:07 AM
You can implement something like this.....

                        <Style TargetType="{x:Type ComboBox}">
                            <EventSetter Event="KeyDown" Handler="ComboBoxColumn_KeyDown"></EventSetter>

        private void ComboBoxColumn_KeyDown(object sender, KeyEventArgs e)
            if (e.Key == Key.Delete)
                ComboBox cb = sender as ComboBox;
                if (cb != null)
                    cb.SelectedIndex = -1;
                    e.Handled = true;

This basically unselects the combobox in edit mode when the delete key is hit.