Unselect item in Combobox in DataGrid

Feb 2, 2009 at 6:59 PM
Edited Feb 2, 2009 at 6: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? 
Coordinator
Feb 3, 2009 at 11:07 PM
You can implement something like this.....

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

        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.