我指定了单元格的右键菜单:
DataGridViewRow row = (DataGridViewRow)this.dataGridView1.RowTemplate.Clone();
DataGridViewTextBoxCell celluser = new DataGridViewTextBoxCell();
cell.ContextMenuStrip = contextMenuStrip1;但是我想在菜单点击事件中获得点击的那个单元格在哪一列、哪一行,请高手指点一下小弟。
private void 右键按钮1ToolStripMenuItem_Click(object sender, EventArgs e)
{
//如何获得所在列和行,包括单元格的内容???????
}
DataGridViewRow row = (DataGridViewRow)this.dataGridView1.RowTemplate.Clone();
DataGridViewTextBoxCell celluser = new DataGridViewTextBoxCell();
cell.ContextMenuStrip = contextMenuStrip1;但是我想在菜单点击事件中获得点击的那个单元格在哪一列、哪一行,请高手指点一下小弟。
private void 右键按钮1ToolStripMenuItem_Click(object sender, EventArgs e)
{
//如何获得所在列和行,包括单元格的内容???????
}
解决方案 »
- c#进行调用c++封装程序
- webform中,CheckBox的Checked属性无法获取,在线等
- jQuery怎么实现文本框的ToolTip效果
- 字符所在字符串的位置
- 使用多个异步POST请求 连续循环执行为什么反应变得越来越慢
- datagridview高手请进了!
- C#正则表达式的问题
- Visual Studio 2003中引用acdbmgd.dll和acmgd.dll出错???
- 不知道放这里合不合适的问题——.net中的网页框架问题
- 警告The referenced project 'C:\AutoUpdater.csproj' does not exist.
- C#发送邮件
- C# 读取xml字符串中某个节点的属性
for(int i = 0; i < dataGridView1.Columns.Count; i++)
{
Rectangle columnrect = dataGridView1.GetColumnDisplayRectangle(i, false);
if(dataGridView1.RectangleToScreen(columnrect).Contains(p))
{
break;
}
}
{
dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
}private void 右键按钮1ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (dataGridView1.CurrentCell != null)
{
textBox1.Text = dataGridView1.CurrentCell.RowIndex.ToString(); //行索引
textBox2.Text = dataGridView1.CurrentCell.ColumnIndex.ToString(); //列索引
textBox3.Text = dataGridView1.CurrentCell.Value.ToString(); //内容
}
}
DataGridViewCell cell; //MouseRightClick位置的单元格,不一定是当前单元格(dataGridView1.CurrentCell)
private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
DataGridView.HitTestInfo gp = ((DataGridView)sender).HitTest(e.X, e.Y);
if (gp.RowIndex > -1 && gp.RowIndex>-1)
{
cell = ((DataGridView)sender)[gp.ColumnIndex, gp.RowIndex]; // 在右键菜单事件 访问 cell
MessageBox.Show("第" + gp.RowIndex + "行,第" + gp.ColumnIndex + "列");
}
}
}
if (gp.RowIndex > -1 && gp.RowIndex>-1)
{
DataGridView.HitTestInfo gp = ((DataGridView)sender).HitTest(e.X, e.Y);
cell = ((DataGridView)sender)[gp.ColumnIndex, gp.RowIndex]; // 在右键菜单事件 访问 cell
MessageBox.Show("第" + gp.RowIndex + "行,第" + gp.ColumnIndex + "列");
}