【发布时间】:2014-04-25 20:20:49
【问题描述】:
我正在尝试在鼠标单击事件中从 datagridview 中获取价值。
在我单击 datagridview 中的标题之前效果很好。我收到一条错误消息:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name:index
我使用这段代码来检测鼠标点击:
private void dataGridView1_CellMouseClick(Object sender, DataGridViewCellMouseEventArgs e)
{
if (dataGridView1.Rows[e.RowIndex].Index != -1)
{
textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
}
else
{
textBox1.Text = "";
}
}
"dataGridView1.Rows[e.RowIndex].Index != -1" 不工作,我不知道为什么。
任何在标题上禁用鼠标单击事件的简单解决方案都会很棒!谢谢!
我也用:
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
选择整列并且 CellContentClick 不起作用。如果幸运的话,CEllContentClick 可以工作 3/10 次。
【问题讨论】:
标签: c# datagridview click mouse