在右键点击DataGridView的时候,让点击的行成为该DataGridView的CurrentRow. 请教高手您:在右键点击DataGridView的时候,让点击的行成为该DataGridView的CurrentRow.感谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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; }} zestheart(零度经线) ,谢谢⌒⊙⊙⌒。 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()); } } }也是可以的。 谢谢楼上的几位!特别感谢sdl2005lyx() !! 怎样用net use 断开以有的连接。 Socket异步接收与UI线程的交互时发生丢包 帮忙看一下改下 C#读取文件 XmlSerializer 问题 一简单问题 c#:客户端实现根据用户公司代码显示相关EXCEL文件并提供下载问题 C#多线程,关于BackgroundWorker的问题,求高手解决 怎么让它出现在最小化前的Location位置上 1.1和1.0版本可否共存??(不是安装上地。) DropDownList的SelectedValue赋值问题 关于C#做倒计时对话框的问题?
{
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;
}
}
{
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());
}
}
}
也是可以的。