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

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16350 |

    I have a problem if I add new rows to datagrid if the grid is larger than the visible size of the screen and the current position is at the bottom of the datagrid. I would like to ensure that the new row is always visible to the user, but my grid always scroll back to the top row.

    I looked at the examples of Xceed and there is it the same way, that I do not really like.

    Is there any possibility to “ensure” the new row is always be displayed? In a standard treeview control I can call the function “EnsureVisible” of a treenode, so the tree is always scrolled to the right position so the treenode is in the visible area of the treeview control.

     

    Thankx for any feedback

    Oliver

    Imported from legacy forums. Posted by Oliver (had 810 views)

    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)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for your help – it’s working fine [:D]

    Imported from legacy forums. Posted by Oliver (had 1202 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.