C# 如何将焦点设置到datagridview中的特定单元格?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18567143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set focus to a particular cell in datagridview?
提问by user2738864
I am using the following code to focus to a particular cell in DataGridView
.
我正在使用以下代码将焦点放在DataGridView
.
private void dgOrderDetails_CellValueChanged(object sender, DataGridViewCellEventArgs e) {
if (dgOrderDetails.Columns[e.ColumnIndex].Name.ToString().ToUpper() == "BILLINGMONT") {
dgOrderDetails.Focus();
dgOrderDetails.CurrentCell = dgOrderDetails[dgOrderDetails.CurrentCell.ColumnIndex + 1, dgOrderDetails.CurrentCell.RowIndex];
}
}
But my data grid cursor is not binding where I am expecting.
但是我的数据网格游标没有绑定到我期望的地方。
回答by coolprarun
Try this.
尝试这个。
dataGridView1.CurrentCell = desiredCell;
dataGridView1.BeginEdit(true);
Add your desired cell.
添加所需的单元格。
回答by Jeremy Thompson
datagridview.Focus();
datagridview.CurrentCell = datagridview.Rows[1].Cells[2];
回答by shyam
grdUser.CurrentCell = grdUser.Rows[e.RowIndex].Cells[2];
grdUser.CurrentCell.Selected = true;
e.Cancel = true;
回答by Alpha Software
if u want to go to a cell after another, for example go to cells[5] after cells[1] in a current row. I have this problem with datagridview but I found a good way for it: in "CellLeave" event write this codes :
如果您想依次转到一个单元格,例如在当前行中的单元格 [1] 之后转到单元格 [5]。我有 datagridview 的这个问题,但我找到了一个很好的方法:在“CellLeave”事件中编写以下代码:
if (DatagridView.CurrentCell == DatagridView.CurrentRow.Cells[0])
{
SendKeys.Send("{TAB}");
SendKeys.Send("{TAB}");
}
I Go to cells[3] after cells[0]
我在单元格[0]之后转到单元格[3]
I hope it Helps u
我希望它可以帮助你