Open dropdown(in a datagrid view) items on a single click

前端 未结 3 1432
孤街浪徒
孤街浪徒 2020-12-01 20:39

How can i avoid the double click on a DropDownButton used within a DataGridView? Right now I am able to view the drop down items within the D

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 21:39

    The "set EditMode property of the DataGridView to EditOnEnter" worked for me, but I found another problem: user can't delete a row by just selecting and pressing DEL key. So, a google search gave me another way to do it. Just catch the event CellEnter and check if the cell is the appropriated type to perform appropriated action like this sample code:

    private void Form_OnLoad(object sender, EventArgs e){
        dgvArmazem.CellEnter += new DataGridViewCellEventHandler(dgvArmazem_CellEnter);
    }
    
    void dgvArmazem_CellEnter(object sender, DataGridViewCellEventArgs e)
            {
                DataGridView dg = (DataGridView)sender;
    
                if (dg.CurrentCell.EditType == typeof(DataGridViewComboBoxEditingControl))
                {
                    SendKeys.Send("{F4}");
                }
            }
    

    Now the ComboBox drops down faster and the user still delete a row by selecting a row and pressing DEL key.

    That's it.

提交回复
热议问题