为什么在第一次单击时触发了两次DataGridView CellBeginEdit事件?
我正在在DataGridView中获取一个记录列表,其中包含一个复选框。我正在使用 CellBeginEdit 单击复选框时发送数据。在表单加载时,如果未选择复选框,并且我选择了第一个复选框或第一个复选框,它已经检查了,它可以从第一行发送数据,但是如果我选择任何其他复选框,而不是第一个复选框,则 cellbeginedit 是两次触发的,它在第一个触发器上从第一行发送数据,然后从选定的行发送数据。我找不到问题。
这是 listusers_cellbeginedit 在复选框上调用的单击。
private void ListUsers_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
if (ListUsers.Rows[e.RowIndex].Cells[0].Value != null && ListUsers.Rows[e.RowIndex].Cells[1].Value != null)
{
}
}
DataGridView Designer代码
//
// ListUsers
//
this.ListUsers.BackgroundColor = System.Drawing.Color.White;
this.ListUsers.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.ListUsers.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.chkUsers,
this.columnHeader17,
this.columnHeader18});
this.ListUsers.Location = new System.Drawing.Point(-1, -1);
this.ListUsers.MultiSelect = false;
this.ListUsers.Name = "ListUsers";
this.ListUsers.Size = new System.Drawing.Size(598, 425);
this.ListUsers.TabIndex = 0;
this.ListUsers.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.ListUsers_CellBeginEdit);
this.ListUsers.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.ListUsers_CellEndEdit);
this.ListUsers.EditingControlShowing += new System.Windows.Forms.DataGridViewEditingControlShowingEventHandler(this.ListUsers_EditingControlShowing);
这是我找不到问题的 。谁能提供帮助?
I'm fetching a list of records in DataGridView having a checkbox in it. I'm using CellBeginEdit to send data when the checkbox is clicked. On form load, if no checkbox is selected and, I select the first checkbox or the first checkbox is already checked it works fine it sends data from the first row but if I select any other checkbox rather than the first one then CellBeginEdit is triggered twice and it sends data from the first row on the first trigger, and then sends data from the selected row. I'm unable to find the problem.
Here you can find the form image for clarity
Here is the ListUsers_CellBeginEdit that is called on the checkbox click.
private void ListUsers_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
if (ListUsers.Rows[e.RowIndex].Cells[0].Value != null && ListUsers.Rows[e.RowIndex].Cells[1].Value != null)
{
}
}
Here is the DataGridView designer code
//
// ListUsers
//
this.ListUsers.BackgroundColor = System.Drawing.Color.White;
this.ListUsers.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.ListUsers.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.chkUsers,
this.columnHeader17,
this.columnHeader18});
this.ListUsers.Location = new System.Drawing.Point(-1, -1);
this.ListUsers.MultiSelect = false;
this.ListUsers.Name = "ListUsers";
this.ListUsers.Size = new System.Drawing.Size(598, 425);
this.ListUsers.TabIndex = 0;
this.ListUsers.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.ListUsers_CellBeginEdit);
this.ListUsers.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.ListUsers_CellEndEdit);
this.ListUsers.EditingControlShowing += new System.Windows.Forms.DataGridViewEditingControlShowingEventHandler(this.ListUsers_EditingControlShowing);
I'm unable to find the problem. Anyone who can help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论