Hello
We have an issue working with Bands.When the last cell of a child band is commited, a new row is added. But the cursor goes to the next row from his parent band.We want to have the focus in the new row.Is it possible?
This is before add the new row
This is after the row is added
Hi,
What event are you using to add the new row?
What is the user doing to commit the current row?
My guess is that the user is pressed Tab and that you are using either BeforeRowUpdate or AfterRowUpdate to add the new row. This won't work because the focus will always move to the next cell before the new row gets added.
I don't see any simple way around this. What I would do is handle the BeforePerformAction event and watch for an action of NextCellByTab. You would also have to check to make sure the user is in the last cell of the row, which could be tricky, since the user might have rearranged the columns. But basically, by trapping when the user is about to tab out of the last cell of the row with pending changes, you could cancel the action, add the new row, and then set the focus into the first cell of that row.
Hi Mike, sorry for the delay.
I just test your solution and it's works fine.
As you say, the tricky part is how to know which one is the last cell. But, for test it, I asume it's the last col in the display layout.
Here's the code
Private Sub UltraGrid1_BeforePerformAction(sender As Object, e As BeforeUltraGridPerformActionEventArgs) Handles UltraGrid1.BeforePerformAction Dim idBand As Integer = 1 If Me.UltraGrid1.ActiveRow.Band.Index <> idBand Then Exit Sub If e.UltraGridAction = UltraGridAction.NextCellByTab Then ' Dim LastCol As Integer = Me.UltraGrid1.DisplayLayout.Bands(idBand).Columns.Count - 1 If Me.UltraGrid1.ActiveCell.Column.Index = LastCol Then e.Cancel = True Dim oRow As UltraGridRow = Me.UltraGrid1.DisplayLayout.Bands(1).AddNew() UltraGrid1.ActiveCell = oRow.Cells(0) End If End If End Sub
Thanks
Your solution should work fine as long as you are not using RowLayouts and as long as you don't have any hidden columns that happen to end up at the end of the list.
A more reliable way to tell if you are on the last cell in any row is this:
Dim IsLastColumn As Boolean = (Me.UltraGrid1.CurrentState And UltraGridState.CellLast) = UltraGridState.CellLast