Ticket Q147873
Visible to All Users

Refreshing Grid When Using Custom Enumerator

created 16 years ago

hi
i am using a custom collection with a custom enumerator. in the provided example the enumerator is set to not yield the object when the description = "TEST". you will see that if you set the description to "TEST" before binding then the obejct does not display in the grid which is correct.
when clicking the button i am renaming the description of the bound object to "TEST" in code. i am then calling RefreshData(). i would expect the enumerator to be recalled here and the item to dissappear from the grid. but this is not happening. i have tried calling RefreshDataSource, etc but cannot get the item to dissappear when i click the button. please can you help me understand what i am doing wrong. thanks.

Answers approved by DevExpress Support

created 16 years ago (modified 11 years ago)

Hi Martin,
Since the BindingSource class (which is the grid's datasource) implements the IBindingList interface, the RefreshDataSource and RefreshData methods will do nothing. However, I found that even explicit call of the following methods won't cause repopulation of your enumeration:
                bindingSource1.ResetBindings(false);
                bindingSource1.CurrencyManager.Refresh();
So, this issue isn't related to our grid. You'll get the same result with the standard DataGridView. It appears that the only solution is to re-bind the BindingSource:
                bindingSource1.DataSource = null;
                bindingSource1.DataSource = collection;
I'm looking forward to hearing from you.
Thanks,
Michael.

    Comments (2)
    MT MT
    Martin Threlfall 16 years ago

      Hi Michael
      Thanks for investigating this for me. Got a few follow up questions for you in relation to this.
      -Will it make a difference if I don't use the binding source but bind directly to the collection instead?
      -My aim is to be able to automatically filter the grid to not sure any entities which are flagged for deletion. Previously we achieved this by assigning a grid filter on every grid. I thought this would be a less error prone more elegant solution. Have you any suggestions how else I could achieve my objective?
      -With your solution will resetting the datasource have aany negative impacts? i.e. performance, losing grid state etc.?
      thanks

      DevExpress Support Team 16 years ago

        Hi Martin,

        1. The XtraGrid can't be bound directly to your EntityCollection<T>, because it doesn't implement the IList interface. Please refer to the Binding Controls to Data Created at Runtime help topic.
        2. As far as I see, you should create a custom datasource that implements the IList interface, and change the underlying list (or items accessed through indices) as soon as the object property is changed. So, when you call the RefreshData method, the grid will access proper objects through certain indices.
        3. Since XtraGrid doesn't cache data internally, resetting the datasource shouldn't affect performance dramatically. Besides, if you reset the datasource, the XtraGrid will try to restore its previous state. To resolve remaining issues, please try the solution provided in the following article:
          How to preserve the XtraGrid View state.
          Thanks,
          Michael.

        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.