问题
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