DataGrid 单击行事件解决方法
DataGrid 单击行事件
我有一个DataGrid,想单击某一行的时候,获取改行数据,然后根据改行数据判断是否要显示另外一个DataGrid。我用了MouseLeftButtonDown怎么是双击才有效果?
------解决方案--------------------
CellDoubleClick事件试试
------解决方案--------------------
你用mousedown事件,然后在事件里面判断是左还是右。这样比较好。
------解决方案--------------------
我有一个DataGrid,想单击某一行的时候,获取改行数据,然后根据改行数据判断是否要显示另外一个DataGrid。我用了MouseLeftButtonDown怎么是双击才有效果?
------解决方案--------------------
CellDoubleClick事件试试
------解决方案--------------------
你用mousedown事件,然后在事件里面判断是左还是右。这样比较好。
------解决方案--------------------
- C# code
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) {//选中单元格,弹出快捷菜单。 if (e.Button == MouseButtons.Right) { if (e.RowIndex >= 0) { this.dataGridView1.ClearSelection(); this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true; this.dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; //右击时选中 contextMenuStrip1.Show(MousePosition.X, MousePosition.Y); }