I have a requirement to make a grid used entirely for data entry. Once the user tabs off the last cell of the last row, the grid needs to grow a new row where data entry can continue (they don't want an add row in the grid, they want the grid to take care of it).
I have been able to successfully add the row without a problem and I have been able to set the correct cell to be active. However, I still have to click in the cell to continue the data edit and the users don't want to have to do this click action. They want to just be able to keep on typing. I will include the code snippet on how to add the blank row, but as I will point out by the screen shot, it doesn't take it all the way to entering edit mode. Any ideas?
Private Sub CellExitedEditMode(sender As System.Object, e As Infragistics.Controls.Grids.ExitEditingCellEventArgs) Handles dgDataEntry.CellExitingEditMode Dim dgRow As Row = Nothing Dim dgRows As RowCollection = Nothing If Not e.Cell Is Nothing Then Select Case e.Cell.Column.Key.ToLower() Case "notes" ' see if on the last row... If e.Cell.Row.Index = Me.dgDataEntry.Rows.Count - 1 Then dgRow = Me.dgDataEntry.Rows.CreateItem() Me.dgDataEntry.Rows.Insert(e.Cell.Row.Index + 1, dgRow) ' set the first cell in the newly added row to being edited Me.dgDataEntry.Rows(Me.dgDataEntry.Rows.Count - 1).Cells(0).IsActive = True Else End If Case Else End Select End If End Sub
My screen shot didn't get posted...try again...
Another approach I have taken is to try and manually entereditmode for that activated cell once the active cell is changing, but it does a strange things with drawing a box around the contents of the added text and then not retaining the values entered...
Private Sub dgDataEntry_ActiveCellChanging(sender As Object, e As Infragistics.Controls.Grids.ActiveCellChangingEventArgs) Handles dgDataEntry.ActiveCellChanging Dim c As Cell = Nothing If Me._blnRowAdded = True Then Me._blnRowAdded = False c = Me.dgDataEntry.Rows(Me.dgDataEntry.Rows.Count - 1).Cells(0) If Me.dgDataEntry.EnterEditMode(c) = False Then MessageBox.Show("Could not place cell in edit mode") End If End If End Sub
Uh, nevermind. It turns out if I move my logic to a later event like CellControlAttached, then this works fine.
_blnRowAdded is a class boolean set when a new row was programmitcally added to the grid in another event.
Private Sub dgDataEntry_CellControlAttached(sender As Object, e As Infragistics.Controls.Grids.CellControlAttachedEventArgs) Handles dgDataEntry.CellControlAttached Dim c As Cell = Nothing If Me._blnRowAdded = True Then Me._blnRowAdded = False c = Me.dgDataEntry.Rows(Me.dgDataEntry.Rows.Count - 1).Cells(0) If Me.dgDataEntry.EnterEditMode(c) = False Then MessageBox.Show("Could not place cell in edit mode") End If Me.dgDataEntry.EnterEditMode() End If End Sub
Hello Alan,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.