I try to insert a new row in a grid and then set a cell automatically to edit mode. The row is inserted via databinding to a business object, and not directly to the grid. The row is highlighted but no cell is in edit mode. If I first click on the grid and then inserts a new row it works for every new row thereafter. It's look like I am missing something the mouseclick do. A row insert is done by adding a new business object, and I deal with the new row in InitializeRow like this:
{
e.Row.Activate();
grid.ActiveCell = aCell;
}
The PerformAction seems to have no effect. If I click the grid first, it works as expected.
Some suggestion?
Kind Regards
Magnus
Oslo, Norway
Here's what I use for doing what you ask:
private void csfGridIkkeBehandletNemd_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) { UltraGrid grid = (UltraGrid)sender; e.Row.Activate(); UltraGridCell aCell = e.Row.Cells["Tekst"]; grid.ActiveCell = aCell; grid.PerformAction(UltraGridAction.EnterEditMode, false, false); grid.ActiveCell.SelStart = 0; }
Thanks.
But it seems that PerfomAction have no effect. I get an error if i try to do SelStart after
grid.PerformAction(UltraGridAction.EnterEditMode)
Error: (selStart are not supported while the cell is not in edit mode)
That's strange since I use similar code, but in a different event firing and it works perfectly. Here's the snippet of code from my own source that works.
UltraGridRow newrow = quoteWorkScopeUltraGrid.DisplayLayout.Bands[0].AddNew(); quoteWorkScopeUltraGrid.ActiveRow = newrow; quoteWorkScopeUltraGrid.ActiveCell = newrow.Cells[2]; quoteWorkScopeUltraGrid.PerformAction(UltraGridAction.EnterEditMode, false, false); quoteWorkScopeUltraGrid.ActiveCell.SelStart = 0;
I'm not sure exactly what this code is intended to do - but calling EnterEditMode in the InitializeRow event seems like a really bad idea. This event fires quite often. It will fire any time a row loads for the first time and it will fire any time any data in the row is changed. So this code is going to constantly be forcing the last row that is initialized to be the active row and go into edit mode. It's going to cause all sorts of conflicts with whatever the application or the user is doing to interact with the grid.
But I don't understand why this code never will set the active cell in edit mode. It works only if the user first mouseclick the grid.
An observation, the event AfterRowInsert is not fired when a row is inserted via databinding.
How about using a method like this:
private void YourUltraGrid_AfterRowInsert(object sender, Infragistics.Win.UltraWinGrid.RowEventArgs e) { YourUltraGrid.ActiveRow = e.Row; YourUltraGrid.ActiveCell = e.Row.Cells["FirstColumnName"]; YourUltraGrid.PerformAction(UltraGridAction.EnterEditMode, false, false); YourUltraGrid.ActiveCell.SelStart = 0; }
This uses the AfterRowInsert of the grid, and worked perfectly when I tested it on a project this morning. Good luck!
It should have work. But I get an error on selstart ( not supported while cell is not in edit mode). Maybe it has something to do with the databinding? I got no error if I mouse click the grid first.
BTW: AfterRowInsert is not fired in my case, but a row is in fact inserted.
I have tried to change the code and moved all the row insert into the click event for the "insert new row button".
// Insert a new object. The grid will then automatically insert a new row via bindingsource
// Norwegian word is not easy to read for you but it is something like this if the grid is databind to objectcollection called BOCollection:
// BOCollection.Add(New BOItem(Id));
// Jump to the last newly created row. This PerformAction work fine.
// Set the column "Tekst" in the active row as activ cell.
csfGridcsfIkkeBehandletNemd.ActiveCell = cell;
// Try to set active cell in editmode. This does not work. No errormessage
// The next statement will trigger an error message "... are not supported while cell is not in editmode)
cell.SelStart = 0;
Sorry for digging out such an old post ... Google send me here after searching for a solution to this exact same problem I had at work. Took a while to explore everything and finally we found out the cause of the error : the cell activation mode was set as "NoEdit" in the initialization of the Form.
Columns("NewDelai").CellActivation = Activation.NoEdit
so whenever we try to force the edit mode on this cell programmatically, we ended up with the same error OP got. ugRapport.PerformAction(UltraGridAction.EnterEditMode) ugRapport.ActiveCell.SelStart = 0
Hope this can help others too !
By trial and error...I've fixed the problem -- or at least worked around it. This is a threading issue on the Ultragrid. If I call: grid.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode) directly (on the first row, first cell) it just doesn't work. However, if I set up a delegate and invoke the delegate, it works fine:
Private Delegate Sub PerformAction()
Sub WinGridPerformAction() grid.PerformAction(Infragistics.Win.UltraWinGrid.UltraGridAction.EnterEditMode) End Sub
Sub InitGrid() grid.DataSource = myDataSource grid.Focus() grid.DisplayLayout.Rows(0).Cells(0).Activate() Me.BeginInvoke(New PerformAction(AddressOf WinGridPerformAction)) End Sub
I am having the exact same problem. Can anyone help?
No matter what I do and where I do it, the first cell is active, but will not enter edit mode without a mouse click.
the row is active, teh cell is active, but Performaction(.....EnterEditMode) just doesn't make it go into edit mode! ARRRGGGH driving me nuts.
maggreen: did you find any solution for this? I am having the exact problem.
I managed to work around this with the following code:
row.Cells(0).Activate()
grid.PerformAction(UltraGridAction.FirstCellInRow)