我有一个单元格单击DataGrid视图中的事件以显示消息框中单击单元格中的数据。我有它设置为它仅适用于某一列且仅当有数据在小区datagridview单元格单击事件
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex.Equals(3))
if (dataGridView1.CurrentCell != null && dataGridView1.CurrentCell.Value != null)
MessageBox.Show(dataGridView1.CurrentCell.Value.ToString());
}
然而,每当我点击任何列标题,一个空白消息框显示出来。我无法弄清楚为什么,有什么提示?
谢谢这个伟大的工作 – Stonep123
只需注意你应该第一个条件之前检查'dataGridView1.CurrentCell!= NULL'... – MatanKri