DateGridView 那个事件是响应鼠标右键的??? 我想鼠标右键单击一行,然后这行被选中,再弹出快捷菜单。快捷菜单是系统默认可以的,请问怎么选中点击的行? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 添加如下的事件处理:private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e){ if (e.Button == MouseButtons.Right) { this.dataGridView1.CurrentCell = this.dataGridView1[e.ColumnIndex, e.RowIndex]; }} 首先你要一行被选中的话,需要设定this.SelectionMode = DataGridViewSelectionMode.FullRowSelect;其次,判断鼠标点击事件应该在MouseUp中,而不是MouseDown.因为快捷菜单最终是在鼠标释放后才出来的,而不是一按下鼠标就出来.你可以随便找个地方看下就知道了.dataGridView1.CellMouseUp += new DataGridViewCellMouseEventHandler(m_gridControl_CellMouseUp);private void m_gridControl_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e){ if (e.Button == MouseButtons.Right) { this.dataGridView1.CurrentCell = this.dataGridView1[e.ColumnIndex, e.RowIndex]; }} 两位都漏了一句: dataGridView1.Rows[e.RowIndex].Selected = true;//使行处于选中状态 设置了currentcell后,这个行自然就是selected = true了. 不需要再设置. 求教:C#与Sql Server镜像服务器连接字符串 asp.net实现相册功能和如何可以把优酷、土豆、51等视频网站的内容链接到并显示在自己的空间播放 怎样用vs2008 自带的水晶报表 服务器未能识别 HTTP 标头 SOAPAction 的值 打开新界面,不能操作主界面 新手学习C#,求基础的实例代码 c#如何检查端口被使用了 急:为什么提示“未将对象引用设置到对象的实例”。 c# winform webbrowser 取网页内容 树形结构 c#.net常用的小函数和方法集 ##############快来帮我
private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
this.dataGridView1.CurrentCell = this.dataGridView1[e.ColumnIndex, e.RowIndex];
}
}
private void m_gridControl_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
this.dataGridView1.CurrentCell = this.dataGridView1[e.ColumnIndex, e.RowIndex];
}
}
dataGridView1.Rows[e.RowIndex].Selected = true;//使行处于选中状态