DataGridViewComboBoxCell忽略第一次单击 [英] DataGridViewComboBoxCell ignores first click

查看:73
本文介绍了DataGridViewComboBoxCell忽略第一次单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新手,我有一个问题,我可以找到类似的贴子,但没有什么可以解决我的问题:



我有一个带有用户控件的窗体,它包含一个DataGridView,它包含一个DataGridViewComboBoxColumn,它包含DataGridViewComboBoxCells。

自动生成的方法是

  private   void  InitializeComponent()
{
.UnitsTerms = new System.Windows.Forms.DataGridViewComboBoxColumn();
等...
}





当我运行我的应用程序时,我第一次点击组合框单元格,忽略点击。下次单击它时,组合框被激活,它允许我从下拉列表中选择。如果我为单元格添加事件管理器,则在第一次单击时输入,但我仍然需要再次单击以更改组合框值。

解决方案

< blockquote>阅读: http:/ /msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellcontentclick%28v=vs.85%29.aspx [ ^ ]



备注:





单击单元格内容时会发生此事件。当按钮单元格或复选框单元格具有焦点时,用户按下并释放空格键时也会发生这种情况,如果在按空格键的同时单击单元格内容,则会发生两次这些单元格类型。



使用此事件检测DataGridViewButtonCell的按钮点击或DataGridViewLinkCell的链接点击。



在DataGridViewCheckBoxCell中,此事件发生在复选框更改值之前,因此如果您不想根据当前值计算预期值,则通常会处理DataGridView.CellValueChanged事件。因为该事件仅在提交用户指定的值时发生(通常在焦点离开单元格时发生),所以还必须处理DataGridView.CurrentCellDirtyStateChanged事件。在该处理程序中,如果当前单元格是复选框单元格,则调用DataGridView.CommitEdit方法并传入Commit值。



有关处理事件的更多信息,看消费事件。





可能需要使用其他活动。


Hi, I am new to C# and I have a problem that I can find vaguely similar postings for but nothing that quite solves my problem:

I have a form with a user control which contians a DataGridView, which contains a DataGridViewComboBoxColumn, which contains DataGridViewComboBoxCells.
The automatically generated method is

private void InitializeComponent()
{
   this.UnitsTerms = new System.Windows.Forms.DataGridViewComboBoxColumn();
   etc...   
}



When I run my application, the first time I click on the combo box cell, the click is ignored. the next time I click it the combo box is activated and it allows me to select from the drop down list. If I add an event andler for the cell, then this is entered on the first click, but I still have to do a second click to change the combo box value.

解决方案

Read this: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellcontentclick%28v=vs.85%29.aspx[^]

Remarks:



This event occurs when the cell content is clicked. It also occurs when the user presses and releases the SPACEBAR while a button cell or check box cell has focus, and will occur twice for these cell types if the cell content is clicked while pressing the SPACEBAR.

Use this event to detect button clicks for a DataGridViewButtonCell or link clicks for a DataGridViewLinkCell.

For clicks in a DataGridViewCheckBoxCell, this event occurs before the check box changes value, so if you do not want to calculate the expected value based on the current value, you will typically handle the DataGridView.CellValueChanged event instead. Because that event occurs only when the user-specified value is committed, which typically occurs when focus leaves the cell, you must also handle the DataGridView.CurrentCellDirtyStateChanged event. In that handler, if the current cell is a check box cell, call the DataGridView.CommitEdit method and pass in the Commit value.

For more information about handling events, see Consuming Events.



Probably, you need to use another event.


这篇关于DataGridViewComboBoxCell忽略第一次单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆