I have a grid where the first column is read-only and the remaining cells are editable.
I have tabbing set to NextCell. What I want is for a user to be able to tab into a new row and have focus set to the first editable cell in edit mode.
The following code works when I insert a stopper in the beginning of the event and step through; however, without the stopper it works, but then returns focus to the first cell in the row, causing a flicker, plus not doing what I want.
Private Sub grdAccountSettings_AfterRowActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdAccountSettings.AfterRowActivate Try If Not _OnInit Then If grdAccountSettings.ActiveRow.Index > 0 And (grdAccountSettings.ActiveCell Is Nothing OrElse grdAccountSettings.ActiveCell.Column.Index = 0) Then grdAccountSettings.ActiveRow.Cells(1).Activate() grdAccountSettings.PerformAction(UltraGridAction.EnterEditMode, False, False) End If End If Catch ex As Exception Debug.Write(ex.Message) End Try End Sub
Using the TabStop = false, I actually had to keep the GotFocus code in order to force the first cell into edit mode, but I was able to get rid of the BeforeCellActivate code.
Yeah, that sounds much better! Thanks!
I think an easier way to do this is to just set TabStop to false on the columns that do not allow editing.
I was able to get it to work by combining the code above with the following code:
Private Sub grdAccountSettings_BeforeCellActivate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CancelableCellEventArgs) Handles grdAccountSettings.BeforeCellActivate If e.Cell.Column.Index = 0 Then e.Cell.Row.Activate() grdAccountSettings.ActiveRow.Cells(1).Activate() grdAccountSettings.PerformAction(UltraGridAction.EnterEditMode, False, False) e.Cancel = True End If
End Sub
Actually, please excuse the code in my previous post. Here is the code I am dealing with. The problem is the same - there is currently no code in my AfterRowActivate event; however, if a put a stopper in the second If/Then of my GotFocus event, I get the correct behavior.
Private Sub grdAccountSettings_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdAccountSettings.GotFocus Try If Not _OnInit Then 'AF 9/17/2010 If grdAccountSettings.ActiveRow IsNot Nothing AndAlso (grdAccountSettings.ActiveCell Is Nothing OrElse grdAccountSettings.ActiveCell.Column.Index = 0) Then grdAccountSettings.ActiveRow.Cells(1).Activate() grdAccountSettings.PerformAction(UltraGridAction.EnterEditMode, False, False) If Not grdAccountSettings.Focused AndAlso grdAccountSettings.ActiveCell IsNot Nothing Then Dim elem As UIElement = grdAccountSettings.ActiveCell.GetUIElement Dim embeddableElement As EmbeddableUIElementBase = TryCast(elem.GetDescendant(GetType(EmbeddableUIElementBase)), EmbeddableUIElementBase) grdAccountSettings.ActiveCell.EditorResolved.EnterEditMode(embeddableElement) End If End If ' grdAccountSettings.DisplayLayout.Override.ActiveAppearancesEnabled = DefaultableBoolean.True End If
Catch ex As Exception MessageBox.Show(MessageBox.Show(MyBase.LogError(ex))) End Try End Sub