Home Forums WinForms controls Xceed Grid for WinForms New row should always be in visible area of the grid – like "EnsureVisible" in a standard TreeViewNode Reply To: New row should always be in visible area of the grid – like "EnsureVisible" in a standard TreeViewNode

User (Old forums)
Member
Post count: 23064

There is not such property on the Row class.  However, you can do this by using event handlers, so to bring into view the row which was just added.  Here is a code snippet showing how you can do this :

private void Form1_Load(object sender, EventArgs e)

{

    //You can fill the grid first before subscribing to this event, if you don’t want this event to be triggered when the grid is first loaded.

    gridControl1.AddingDataRow += new AddingDataRowEventHandler( gridControl1_AddingDataRow );

}

private Xceed.Grid.DataRow rowBeingInserted;

//This event is triggered when the InsertionRow starts to be edited.

void gridControl1_AddingDataRow( object sender, AddingDataRowEventArgs e )

{

    rowBeingInserted = e.DataRow;

    //Let’s be noticed when the row is finished being edited

    rowBeingInserted.EditEnded += new EventHandler( rowBeingInserted_EditEnded );

    rowBeingInserted.EditCanceled +=

new EventHandler( rowBeingInserted_EditCanceled );

}

//The row is inserted, let’s bring it into view and remove the event handlers subscriptions

void rowBeingInserted_EditEnded( object sender, EventArgs e )

{

    rowBeingInserted.BringIntoView();

    rowBeingInserted.EditEnded -=

new EventHandler( rowBeingInserted_EditEnded );

    rowBeingInserted.EditCanceled -=

new EventHandler( rowBeingInserted_EditCanceled );

}

//The row is not inserted (user pressed ESC), let’s remove the event handlers subscriptions

void rowBeingInserted_EditCanceled( object sender, EventArgs e )

{

    rowBeingInserted.EditEnded -=

new EventHandler( rowBeingInserted_EditEnded );

    rowBeingInserted.EditCanceled -=

new EventHandler( rowBeingInserted_EditCanceled );

}

 

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