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.
Refreshing Grid When Using Custom Enumerator
Answers approved by DevExpress Support
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.
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
Hi Martin,
- 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.
- 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.
- 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.