[英]How to set focus to a particular cell in datagridview?
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. 但是我的数据网格游标没有绑定到我期望的位置。
Try this. 尝试这个。
dataGridView1.CurrentCell = desiredCell;
dataGridView1.BeginEdit(true);
Add your desired cell. 添加所需的单元格。
datagridview.Focus();
datagridview.CurrentCell = datagridview.Rows[1].Cells[2];
if u want to go to a cell after another, for example go to cells[5] after cells[1] in a current row. 如果您要一个接一个地去一个单元格,例如在当前行的cell [1]之后去cell [5]。 I have this problem with datagridview but I found a good way for it: in "CellLeave" event write this codes :
我在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 希望对您有帮助
grdUser.CurrentCell = grdUser.Rows[e.RowIndex].Cells[2];
grdUser.CurrentCell.Selected = true;
e.Cancel = true;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.