Sto*_*123 7 c# datagridview cell
我有一个事件,在数据网格视图中单击一个单元格,以在消息框中的单击单元格中显示数据.我将它设置为仅适用于某个列的位置,并且仅当单元格中有数据时才设置
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());
}
Run Code Online (Sandbox Code Playgroud)
但是,每当我单击任何列标题时,都会显示一个空白消息框.我无法弄清楚为什么,任何提示?
Sau*_*R S 23
您还需要检查单击的单元格是否不是列标题单元格.像这样:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex.Equals(3) && e.RowIndex != -1){
if (dataGridView1.CurrentCell != null && dataGridView1.CurrentCell.Value != null)
MessageBox.Show(dataGridView1.CurrentCell.Value.ToString());
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
72007 次 |
| 最近记录: |