Ticket Q246526
Visible to All Users

How to keep unchanged scroll position when refreshing grid data_

created 15 years ago

Hello,
I'm currently trying to solve a similar problem - forcing Xtra GridControl's GridView to keep its scroll position when refreshing data. I'm calling RefreshData() on GridView in the case of some changes made to the data (some records added) and I would like to achieve the effect of scroll position not being moved when refreshing the grid view.
I'm trying to keep the scroll position where it is after executing RefreshData() by changing the value of TopRowIndex property (loading a previously saved TopRowIndex and setting the property back to this value) on GridView, but - to no avail. Even though I change the TopRowIndex after executing RefreshData(), the TopRowIndex value is automatically reverted to 0.
Is there any way it would be possible to keep the scroll position after calling RefreshData()? I would like the scroll position to be kept in a way that user does not see the top visible row being moved up and down.
I also tried to refresh the entire Gridview contents in other ways - by implementing IBindingList and posting a ListChangedType.Reset event. Unfortunately, the refresh behavior is the same - and I cannot revert the TopRowIndex.

Answers approved by DevExpress Support

created 15 years ago (modified 11 years ago)

Hello,
It is not necessary to force the grid to reload all changes when adding new records to the underlying data source. All you need is to properly implement the IBindingList interface. The easiest way to achieve this goal is to use a generic BindingList class. I have attached a sample project, which demonstrates how to implement this feature. Please review it and inform me whether this approach suits your needs.
Thanks,
Stan.

    Comments (2)
    Anatol (DevExpress) 15 years ago

      Hello Krzysztof,
      Please try to use the following code:

      C#
      gridControl1.BeginUpdate(); gridView1.RefreshData(); gridControl1.EndUpdate();

      It works fine for me. Please let me know whether the issue is resolved.
      Thanks,
      Anatol

      Anatol (DevExpress) 15 years ago

        Hello Krzysztof,
        It appears that this behavior is related to your implementation of server mode datasource. For example, when I use the XPServerCollectionSource as the GridControl's datasource, and execute the following code:

        C#
        private void simpleButton1_Click(object sender, EventArgs e) { // Add record PersistentObject1 po1 = new PersistentObject1(); po1.Save(); int index = gridView1.TopRowIndex; int focusedRow = gridView1.FocusedRowHandle; gridControl1.BeginUpdate(); // Refresh GridControl's datasource xpServerCollectionSource1.Reload(); gridView1.FocusedRowHandle = focusedRow + 1; gridView1.TopRowIndex = index + 1; gridControl1.EndUpdate(); }

        the TopRowIndex property isn't reset to 0, the GridControl is updated properly, and the TopRowIndex is changed unnoticeably. To my understanding, the difference is that when a new record is added to your datasource, it is placed to the GridControl immediately, and as a result, the TopRowIndex is shifted. Then you call the RefreshData, which takes a noticeably long time, and only after that the TopRowIndex is incremented. If so, please try to increment the TopRowIndex before calling the RefreshData method, or call the BeginUpdate method before adding a new record to the datasource.
        It this doesn't help, please provide a sample project, reproducing the issue, because I cannot reproduce it using XPServerCollectionSource.
        Thanks,
        Anatol

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.