c# - CellContentClick 事件并不总是有效

标签 c# winforms

CellContentClick 事件并不总是有效 - 它有时有效,有时无效,这是随机的。

我的代码在下面,我正在使用断点进行检查,但程序有时会进入 block ,有时不会。为什么会这样?

private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
    textBoxUserName.ReadOnly = true;
    button2.Visible = true;
    int index = e.RowIndex;
    if (!(index < 0))
    {
        DataGridViewRow row = dataGridView1.Rows[index];
        textBoxUserName.Text = row.Cells["UserNAme"].Value.ToString();
        textBoxPassword.Text = row.Cells["Pass"].Value.ToString();
        dataGridView1.Focus();
    }
    dataGridView1.Focus();
}

最佳答案

尝试使用 CellClick事件代替:

Occurs when any part of a cell is clicked.

CellContentClick单击单元格时不一定会触发事件,用户必须单击单元格的“内容”区域,例如文本,例如:

Occurs when the content within a cell is clicked.

关于c# - CellContentClick 事件并不总是有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22489156/

相关文章:

c# - 折叠 'button' 用于 splitcontainer 控件

c# - Ranorex 测试自动化问题 : Unable to reliably click a button on silverlight web app

c# - Invalidate() 和 Refresh() 都不会调用 OnPaint()

C# WinForms 如何同时播放 2 个声音

c# - 将 MSBuild 生成的文件添加到 Visual Studio 解决方案资源管理器

c# - 将数据从 Controller 绑定(bind)到 View -> Control

c# - 如何在CheckedListBox中显示一些记录

c# - 解耦架构

c# - 静态调用实例方法

c# - 如何使用 linq-c# 将 XML 元素值转换为 int