DatagridView - modifying the data collection



I have a datagridview to which I bind a collection like
LanguageGridView.DataSource = languageCollection;
Later I remove a language object from languageCollection, so the
languageCollection.Count changes from say 20 to 19. Then i try to bind the
data again
LanguageGridView.DataSource = languageCollection;
But i get an error saying
"System.IndexOutOfRangeException. Index 19 does not have a value
at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)..."
How can I show the updated collection in the grid. I have tried Rows.Clear
but since my datacollection doesn't implement IBindingList it doesn't work



Bob Powell [MVP]

Your collection obviously doesn't implement IBindingList, IListChanged or
one of the other interfaces designed for the purpose.

Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting

Find great Windows Forms articles in Windows Forms Tips and Tricks

Answer those GDI+ questions with the GDI+ FAQ

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question