Csharp/C#教程:一键直接访问DataGridViewcombobox?分享


一键直接访问DataGridViewcombobox?

单击一次以在datagridview中选择一行,然后再次单击以单击该行中的控件(在本例中为combobox),我感到很恼火。

有没有办法配置这个东西,所有这一切都可以通过一次鼠标点击而不是两个?

将DataGridView控件的EditMode属性更改为“EditOnEnter”。 这会影响所有列。

如果要有选择地将单击编辑应用于某些列,可以在MouseDown事件期间切换当前单元格以消除要编辑的单击:

// Subscribe to DataGridView.MouseDown when convenient this.dataGridView.MouseDown += this.HandleDataGridViewMouseDown; private void HandleDataGridViewMouseDown(object sender, MouseEventArgs e) { // See where the click is occurring DataGridView.HitTestInfo info = this.dataGridView.HitTest(eX, eY); if (info.Type == DataGridViewHitTestType.Cell) { switch (info.ColumnIndex) { // Add and remove case statements as necessary depending on // which columns have ComboBoxes in them. case 1: // Column index 1 case 2: // Column index 2 this.dataGridView.CurrentCell = this.dataGridView.Rows[info.RowIndex].Cells[info.ColumnIndex]; break; default: break; } } } 

当然,如果您的列及其索引是动态的,则需要稍微修改一下。

通过将DataGridView的EditMode属性设置为EditOnEnter并创建EditingControlShowing事件并添加代码以在此事件中下拉combobox,我能够通过单击鼠标来激活combobox并将其下拉。

有关详细信息,请查看 – https://newapputil.blogspot.in/2015/08/add-combo-box-in-cell-of-datagridview.html

上述就是C#学习教程:一键直接访问DataGridViewcombobox?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/949074.html

(0)
上一篇 2021年11月17日
下一篇 2021年11月17日

精彩推荐