AcceptChanges causes unwanted GridView behavior

3 posts, 0 answers
  1. Robert
    Robert avatar
    9 posts
    Member since:
    Apr 2011

    Posted 28 Sep 2011 Link to this post

    I have an application with 3 GridViews bound to 3 datatables.  I use a single VB subroutine with the GridView as an argument to write changes in these datatables to an Oracle database.  In this subroutine, after the database has been updated, I call RadGridView.DataSource.AcceptChanges to reset all the data row states.  My problem is this:

    In a GridView with, let's say 500 rows, I select row 250 and position it in the middle of the displayed rows.  After the save routine completes and RadGridView.DataSource.AcceptChanges is called, the GridView refreshes and the selected row is now displayed at the top of the GridView.  This behavior disrupts the users' workflow.  Is there any way I can suppress this refresh?

    Robert S.
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 30 Sep 2011 Link to this post

    Hello Robert,

    No, but you can always save the currentRowIndex and reset it on data binding complete, like so:
       _radGridView.DataBindingComplete += new GridViewBindingCompleteEventHandler(_radGridView_DataBindingComplete);
        _selectedRowIndex = _radGridView.CurrentRow.Index;
        // update datasource here
    void _radGridView_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
        if (_selectedRowIndex != 0 && _radGridView.RowCount > _selectedRowIndex)
            _radGridView.CurrentRow = _radGridView.Rows.ElementAt(_selectedRowIndex);

     Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  3. DevCraft banner
  4. Jack
    Jack avatar
    2335 posts

    Posted 03 Oct 2011 Link to this post

    Emanuel, thank you for your suggestion.

    Robert, when calling the AcceptChanges method, the associated currency manager resets its position and this change is reflected in RadGridView. There is no option to suppress the synchronization with the currency manager. You have to preserve the old current row like Emanuel suggested. You can also save the scrollbar position and restore it when this operation finishes. Here is a sample:
    int value = this.radGridView1.TableElement.VScrollBar.Value;
    this.radGridView1.TableElement.VScrollBar.Value = value;

    I hope this helps. If you need further assistance, do not hesitate to write back.
    Best wishes,
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top