DataGridView中右键获得焦点问题 在DataGridView中,先用左键选中一个单元格,然后再右键点击其他列的列名(columnHeaders),在弹出的右键中选择对该列的处理方式。但是现在,焦点一直在原来左键选定的单元格,对该列的处理变成对选定单元格那列的处理。请问有没有什么好的办法能解决点击右键获得焦点的问题?望高手指点。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void dataGridView1_CellContextMenuStripNeeded(object sender, DataGridViewCellContextMenuStripNeededEventArgs e){ dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];}private void 右键ToolStripMenuItem_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(); } } 谢谢啦。我试了下,虽然能处理事件,不过它的游标的focus还是停留在原来的单元格里。他的要求是,直接能让被点击列名的那列,直接获得focus,并对该列进行处理(比如全选,复制等等),我觉的就像要实现跟点击左键一样的功能,并且还得显示下拉框。你看能实现吗?再次感谢 #region DataGridView 右键选中 /// <summary> /// DataGridView 右键选中 /// </summary> /// <param name="e"></param> private void DataGridMen(DataGridViewCellMouseEventArgs e) { if (e.Button == MouseButtons.Right) { if (e.RowIndex >= 0) { spxxGridView.ClearSelection(); spxxGridView.Rows[e.RowIndex].Selected = true; spxxGridView.CurrentCell = spxxGridView.Rows[e.RowIndex].Cells[e.ColumnIndex]; jyMenu.Checked = Load_spzt(e.RowIndex); DataGrivMenu.Show(MousePosition.X, MousePosition.Y); } } } #endregion private void dgvRoomInfos_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e){ if (e.Button == MouseButtons.Right)//当按下鼠标右键时 { this.dgvRoomInfos.SelectedRows[0].Selected = false;//原来选中行设为false this.dgvRoomInfos.Rows[e.RowIndex].Selected = true;//单击右键这行设为选中 }} Thanks不过怎么还是不行啊,焦点还是移不过去 请问C#如何调用TC编译器。。 关于子类重写父类的方法 字符串[19/Aug/2010:00:06:41 -0400]转换成DateTime类型? 大数据量和病毒防范提问?请各位哥们姐们们帮忙!!! 请教报表制作问题 在线求助,如何实现一个窗体中多次打开另一个窗体 c# webservice 有时无法收到客户端的请求 会有哪些原因 VS.NET C# 程序的自动运行问题 文件上传的aspx怎么超过4M就不能传了? asp在框架frameset中session丢失的问题,在线等急!!!!! vs2008 求电影院管理系统的电影票打印代码
{
dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
}private void 右键ToolStripMenuItem_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();
}
}
我试了下,虽然能处理事件,不过它的游标的focus还是停留在原来的单元格里。
他的要求是,直接能让被点击列名的那列,直接获得focus,并对该列进行处理(比如全选,复制等等),我觉的就像要实现跟点击左键一样的功能,并且还得显示下拉框。
你看能实现吗?再次感谢
#region DataGridView 右键选中
/// <summary>
/// DataGridView 右键选中
/// </summary>
/// <param name="e"></param>
private void DataGridMen(DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (e.RowIndex >= 0)
{
spxxGridView.ClearSelection();
spxxGridView.Rows[e.RowIndex].Selected = true;
spxxGridView.CurrentCell = spxxGridView.Rows[e.RowIndex].Cells[e.ColumnIndex];
jyMenu.Checked = Load_spzt(e.RowIndex);
DataGrivMenu.Show(MousePosition.X, MousePosition.Y);
}
}
}
#endregion
private void dgvRoomInfos_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)//当按下鼠标右键时
{
this.dgvRoomInfos.SelectedRows[0].Selected = false;//原来选中行设为false
this.dgvRoomInfos.Rows[e.RowIndex].Selected = true;//单击右键这行设为选中
}
}
不过怎么还是不行啊,焦点还是移不过去