This is a migrated thread and some comments may be shown as answers.

AcceptChanges causes unwanted GridView behavior

2 Answers 152 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 28 Sep 2011, 03:55 PM
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?

Thanks,
Robert S.

2 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 30 Sep 2011, 05:51 AM
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
0
Jack
Telerik team
answered on 03 Oct 2011, 09:41 AM
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;
((DataTable)this.radGridView1.DataSource).AcceptChanges();
this.radGridView1.TableElement.VScrollBar.Value = value;

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

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

Tags
GridView
Asked by
Robert
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Jack
Telerik team
Share this question
or