我有一個單元格單擊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