C# datagridview內单击右键,如何获得右键单击处datagridview的值???? C# datagridview內 单击右键,如何获得右键单击处datagridview单元格的值????现在我的datagridview里面显示了数据,我需要右击datagridview然后得到点击处datagridview的值,然后根据这个值 做其他的操作。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 I think this will helpful.http://stackoverflow.com/questions/173295/right-click-to-select-a-datagridview-row private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) object selectvalue= this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); } and upI think the second floor is right. 感谢你的答复,现在可以得到值但是如何控制右键菜单出现的位置为鼠标点击的地方呢?也就是怎样得到点击的那个cell控件。 private void dataGridView1_MouseDown(object sender, MouseEventArgs e) { int r = this.dataGridView1.HitTest(e.X, e.Y).RowIndex; int c = this.dataGridView1.HitTest(e.X, e.Y).ColumnIndex; if (r >= 0 && c >= 0) //点中Cell { DataGridViewCell hitcell = this.dataGridView1.Rows[r].Cells[c]; Point pscreen = this.dataGridView1.PointToScreen(e.Location); Point pForm = this.PointToClient(pscreen); this.textBox1.Text = pscreen.ToString(); //相对屏幕的坐标 this.textBox2.Text = pForm.ToString(); //相对当前Form的坐标 } else //没点中Cell { } } ok,thank you very much!!! ~~~~~~~~~~GridView动态设定样式 点关闭窗口按钮时,窗口不能关闭?求解 用c#如何产生随机数 C#中三层架构反射问题 .NET操作xml问题? C#实现修改Excel表格数据 Winform作的文件列表与OS拖动问题! 请教asp.net第三方控件Infragistics的授权问题 请教:建web应用程序,出现配置错误 C语言的动态库在C#中如何声明及调用 这么获取这个字符???不是汉字的? c# winform初学者例子程序
{
if (e.Button == MouseButtons.Right)
object selectvalue= this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
}
I think the second floor is right.
{
int r = this.dataGridView1.HitTest(e.X, e.Y).RowIndex;
int c = this.dataGridView1.HitTest(e.X, e.Y).ColumnIndex;
if (r >= 0 && c >= 0) //点中Cell
{
DataGridViewCell hitcell = this.dataGridView1.Rows[r].Cells[c]; Point pscreen = this.dataGridView1.PointToScreen(e.Location);
Point pForm = this.PointToClient(pscreen);
this.textBox1.Text = pscreen.ToString(); //相对屏幕的坐标
this.textBox2.Text = pForm.ToString(); //相对当前Form的坐标 }
else //没点中Cell
{
} }