سؤال

In plain combobox when comboboxstyle is set as Simple and user something type in the field and then press Enter KeyUp event is fired. In datagridview when I have ComboboxColumn and style set as Simple KeyUp event isn't fired and KeyPress and KeyDown. And I've created my own custom datagridview and KeyUp in editingmode isn't fired too. And I've created my won custom DataGridViewComboBoxCell and OnKeyUp, EnterUnsharesRow, KeyDownUnsharesRow events aren't called. When user type something in this comboboxcell and press Enter this text is cleared. How to commit entered text in the cell and which event is fired?

Thanks

هل كانت مفيدة؟

المحلول

You need to access the underlying editing control during the EditingControlShowing event of the DataGridView.

void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    if (e.Control is DataGridViewComboBoxEditingControl)
    {
        DataGridViewComboBoxEditingControl cb =  
            e.Control as DataGridViewComboBoxEditingControl; 
        cb.DropDownStyle = ComboBoxStyle.Simple;

        cb.KeyUp += new KeyEventHandler(cb_KeyUp);
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top