Home Forums WinForms controls Xceed Grid for WinForms Error leaving the edition of a cell Reply To: Error leaving the edition of a cell

User (Old forums)
Member
Post count: 23064

This will not work. If you reset the grid, the sender row of the LeavingEdit event is not valid anymore.

What you need to do is to search for the corresponding row (through the value of one cell for example) in the new row list, and set it as the current one. You will need to use the Application.Idle event for this to work.

e.g.:
<code>
private void Form1_Load(object sender, System.EventArgs e)
{
foreach( Cell cell in dataRowTemplate1.Cells )
{
cell.LeavingEdit += new LeavingEditEventHandler( cell_LeavingEdit );
}
}

private Int32 supplierID;

private void cell_LeavingEdit( object sender, LeavingEditEventArgs e )
{
Cell cell = sender as Cell;
if( cell != null )
{
e.Cancel = true;
supplierID = ( Int32 )cell.ParentRow.Cells[ “SupplierID” ].Value;
gridControl1.DataSource = suppliersBindingSource;
Application.Idle += new EventHandler( Application_Idle );
}
}

private void Application_Idle( object sender, EventArgs e )
{
Application.Idle -= new EventHandler(Application_Idle);
foreach( Xceed.Grid.DataRow row in gridControl1.DataRows )
{
if( ( Int32 )row.Cells[ “SupplierID” ].Value == supplierID )
{
gridControl1.CurrentRow = row;
gridControl1.SelectedRows.Clear();
gridControl1.SelectedRows.Add( row );
break;
}
}
}
</code>

Imported from legacy forums. Posted by André (had 419 views)