为什么在第一次单击时触发了两次DataGridView CellBeginEdit事件?

发布于 2025-01-22 20:05:28 字数 1933 浏览 1 评论 0原文

我正在在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 enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文