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

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

问题描述

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

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.

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

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();
    }
}

推荐答案

CellContentClick 事件仅在单元格内的内容(文本)被点击时触发.

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

使用 CellClick 事件而不是 CellContentClick,因为该事件在单元格的任何部分被点击时触发(不仅仅是里面的内容)它).

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天全站免登陆