I need to activate the current cell in the _AfterCellUpdate event after the error message is shown to tell the user that the value of the cell is wrong. But the next cell is activated when the tab is pressed.
The code below shows that I am doing everything to keep the focus on the same cell, but the focus is moved to the next cell!
void ultraGridUM_AfterCellUpdate(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { if (e.Cell.Column.Key == "Code" && e.Cell.Value!=null) { foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in this.ultraGridUM.Rows) { if (row != e.Cell.Row) { if (row.Cells["Code"].Value != DBNull.Value) { if (String.Compare(row.Cells["Code"].Value.ToString(), e.Cell.Value.ToString().Trim()) == 0) { MessageBox.Show("Wrong value."); e.Cell.Value = e.Cell.OriginalValue; this.ultraGridUM.ActiveRow = e.Cell.Row; this.ultraGridUM.ActiveCell = e.Cell; this.ultraGridUM.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode,false,false); return; } } } } } }
The best thing to do would be to validate the cell before it it updated, instead of after. Use BeforeCellUpdate and you can cancel the operation and keep the focus in the cell, instead of trying to put it back in after the user already left.
I fount out that e.Cancel will cancel the cell update, but how can I activate that cell? It seems that the cell that I click will activate or the next cell if I use the Tab. Also is there a way to set the last value back?
When I use BeforeCellUpdate and the use CanlUpdate of the e.Cell it does not cancell the cell update and also when I say e.Cell.Activate() it will not activate it and instead it activates the that I click with the mouse.