首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

DataGrid 单击行事件解决方法

2012-03-29 
DataGrid 单击行事件我有一个DataGrid,想单击某一行的时候,获取改行数据,然后根据改行数据判断是否要显示

DataGrid 单击行事件
我有一个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);                } 

热点排行