DataGridView点击事件并不总是触发 [英] DataGridView click event doesn't always fire

查看:442
本文介绍了DataGridView点击事件并不总是触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 DataGridView 。它的 Cell_Content_Click 在我每次选择一个单元格时都不会触发。它会触发,但不会在每次点击。



我想在我的字符串变量'selected'中获取选定单元格的内容。这是我在做什么:

pre $私人无效dataGridView1_CellContentClick(对象发件人,DataGridViewCellEventArgs e)
{
if(dataGridView1.Rows [e.RowIndex] .Cells [e.ColumnIndex] .Value!= null)
{
selected = dataGridView1.Rows [e.RowIndex] .Cells [e.ColumnIndex]。 Value.ToString();
}
}


解决方案


使用 CellClick 事件而不是 CellContentClick ,因为当单击任何 部分时触发该事件(不只是它里面的内容)。


I have a DataGridView. Its Cell_Content_Click is not firing each time I select a cell. It does fires but not at each click.

I want to get content of selected cell in my string variable 'selected'. Here is what I am doing:

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
    {
        selected = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
    }
}

解决方案

The CellContentClick event only fires when the content (text) inside a cell is clicked.

Use the CellClick event instead of CellContentClick, since that event fires when any part of the cell is clicked (not just the content inside it).

这篇关于DataGridView点击事件并不总是触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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