在右键点击DataGridView的时候,让点击的行成为该DataGridView的CurrentRow.

celebrate 2006-12-27 01:13:38

请教高手您:在右键点击DataGridView的时候,让点击的行成为该DataGridView的CurrentRow.

感谢!!
...全文
352 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
celebrate 2006-12-27
  • 打赏
  • 举报
回复
谢谢楼上的几位!

特别感谢sdl2005lyx() !!
bill024 2006-12-27
  • 打赏
  • 举报
回复
不好意思,我的是DataGrid
bill024 2006-12-27
  • 打赏
  • 举报
回复
private void dataGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button==MouseButtons.Right)
{
System.Drawing.Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);
if(hti.Type == DataGrid.HitTestType.Cell)
{
MessageBox.Show(dataGrid1[hti.Row, hti.Column].ToString());
}
}
}
也是可以的。
xray2005 2006-12-27
  • 打赏
  • 举报
回复
学习
sdl2005lyx 2006-12-27
  • 打赏
  • 举报
回复
zestheart(零度经线) ,谢谢⌒⊙⊙⌒。
zestheart 2006-12-27
  • 打赏
  • 举报
回复
路过发现sdl2005lyx() 绝对技术上的好人~~顶一下~~~
sdl2005lyx 2006-12-27
  • 打赏
  • 举报
回复
lz:如果问题还没解决,可直接发短信给我。。。。
sdl2005lyx 2006-12-27
  • 打赏
  • 举报
回复
lz: 解决办法如下:

private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
//取得鼠标点击位置的信息,例如,行索引和列索引
DataGridView.HitTestInfo info = dataGridView1.HitTest(e.X, e.Y);

//取得点击位置的行
DataGridViewRow dgr = dataGridView1.Rows[info.RowIndex];
//设置当前单元格,由于CurrentRow是只读属性,只有借助CurrentCell。
//必须将 CurrentCell 属性设置为所需行中的单元格。
dataGridView1.CurrentCell=dgr.Cells[info.ColumnIndex];

//到此已经将点击的行成为该DataGridView的CurrentRow,下面让其处于选中状态,可以不用
dataGridView1.Rows[info.RowIndex].Selected = true;
}
}
burnett 2006-12-27
  • 打赏
  • 举报
回复
应该自定义事件了~~
帮忙顶。

110,588

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧