Set CurrentCell Focus
-
I'm working with DataGrid in winforms application. I need to set focus() to a specific cell in the DataGrid. I used the CurrentCell property to set the cell focus: private void ColumnChangingHandler(object sender, DataColumnChangeEventArgs args) { switch (args.Column.ColumnName) { case "acsID": { string value = args.ProposedValue.ToString(); if (!IsNumber(value)) { SetCellWithFocus(this.dataGrid2); dataGrid2_GotFocus(sender, args); } break; } } } private void SetCellWithFocus(DataGrid myGrid) { myGrid.CurrentCell = new DataGridCell(1,1); } private void dataGrid1_GotFocus(object sender, EventArgs e) { MessageBox.Show(dataGrid1.CurrentCell.ColumnNumber + " " + dataGrid1.CurrentCell.RowNumber); } but the focus was returned in the next cell. Please help me. Thanks Mr Duc Linh Nguyen
-
I'm working with DataGrid in winforms application. I need to set focus() to a specific cell in the DataGrid. I used the CurrentCell property to set the cell focus: private void ColumnChangingHandler(object sender, DataColumnChangeEventArgs args) { switch (args.Column.ColumnName) { case "acsID": { string value = args.ProposedValue.ToString(); if (!IsNumber(value)) { SetCellWithFocus(this.dataGrid2); dataGrid2_GotFocus(sender, args); } break; } } } private void SetCellWithFocus(DataGrid myGrid) { myGrid.CurrentCell = new DataGridCell(1,1); } private void dataGrid1_GotFocus(object sender, EventArgs e) { MessageBox.Show(dataGrid1.CurrentCell.ColumnNumber + " " + dataGrid1.CurrentCell.RowNumber); } but the focus was returned in the next cell. Please help me. Thanks Mr Duc Linh Nguyen