DatagridView - modifying the data collection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

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