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
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.
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;
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)
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; }