2015-10-05 74 views
2

我正在使用一个DataGridView,它使用包含DataGridViewComboBoxColumn列的几列的设计器创建。DataGridViewComboBoxColumn - 必须单击两次单元格以显示组合框

据略有刺激性,我要对每一个电池点击两次甚至三次,以显示下拉列表:

  1. 如果我点击了文字部分,它需要点击!

enter image description here enter image description here enter image description here

  • 如果我点击向下arroow,只有两个点击:
  • enter image description here enter image description here

    我假设这是由于单元格使用第一次点击来获得焦点,但有没有办法解决这个问题,所以点击一个单元格立即显示组合框?我注意到,使用DataGridViewCheckBoxColumn同样的问题不是发生......单击一个复选框会立即切换它,无论该单元是否有焦点。

    +0

    也许这可以帮助:[http://stackoverflow.com/a/242760/3413552](http://stackoverflow.com/a/242760/3413552) –

    +0

    您可能需要检查[此解决方案。 ](http://stackoverflow.com/questions/34543940/datagridviewcomboboxcolumn-doesnt-open-the-dropdown-on-first-click/39757746#39757746) – TaW

    回答

    4

    您可以简单地设置您的DataGridViewEditOnEnterEditMode财产。

    它使编辑更容易。几乎一次点击,但如果您希望立即为点击ComboBoxColumn的组合框显示下拉内容时发生事件,您可以处理CellClick事件,然后使用网格中的EditingControl,并将其投射到DataGridViewComboBoxEditingControl并使其显示下拉菜单。

    private void categoryDataGridView_CellClick(object sender, DataGridViewCellEventArgs e) 
    { 
        //You can check for e.ColumnIndex to limit this to your specific column 
        var editingControl = this.categoryDataGridView.EditingControl as DataGridViewComboBoxEditingControl; 
        if (editingControl != null) 
         editingControl.DroppedDown = true; 
    } 
    
    • 使用这一招时要小心,你可能会使下拉菜单恼人的用户时,他只希望在单击单元格,而不需要进行编辑。
    相关问题