I defined the AddRow behavior in the InitializeLayout event:
e.Layout.Override.AllowAddNew = AllowAddNew.FixedAddRowOnTop;
and am using a BindingList to control the underlying data of an UltraGrid.
The grid is single-banded with 3 visible columns, two hidden. The first visible column is a ValueList.
When the grid has existing rows, hitting the TAB key after entering data in the third column adds the row to the grid. This AddRow is then grayed-out.
If the grid is empty, terminating data entry in the AddRow at the top of the grid does not end data entry of that new row. The only way to add the row is to hit the RETURN key, which then does add the row to the grid below. However, the AddRow at top is not grayed-out, but has a "0" in each of the three visible columns. Checking the grid.Row.Count shows two rows.
How can I control the row add better, and not add the extraneous row?
Hi Lars,
Thank you for posting in our forums.
When you have rows in the grid, adding the row with the tab key works, because the active row is changed and this updates the grid. In this case you have an “Add Row”, with updated data in it so the grid adds the row to its rows collection. When you don’t have any existing rows the “Add Row” is the only row in the grid, so the active row can’t be changed and the grid can’t be updated this way. By default when you press enter, the data is committed and this adds “Add Row”.
You can change the TabNavigation property to NextControlOnLastCell and then when you have no other rows, pressing tab on the last cell of the “Add Row” will cause the focus to go to the next control and that will update the grid:
ultraGrid1.DisplayLayout.TabNavigation = TabNavigation.NextControlOnLastCell;
When you add a row the grid doesn’t disable the “Add Row”. Your application must have some logic that does this. Are you disabling it in some event? If yes, which event do you use? Please provide me with an isolated sample that reproduces this issue. I will be glad to research it and see what causes this behavior.
Thank you for your collaboration.
I am looking forward to hearing from you.
Thanks so much for the detailed response. The one line fixed the behavior.