DataGridView click event doesn't always fire

家住魔仙堡 提交于 2019-12-12 14:22:43

问题


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

回答1:


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).



来源:https://stackoverflow.com/questions/26690742/datagridview-click-event-doesnt-always-fire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!