Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I m trying to bind a List with DataGridView Datasource


C#
grdView.DataSource=files;
where files is the List


I am assigning the above in a Button Event. I am adding items to the list in the same Button Event . This works fine when I first call the Button Event. Items get populated on the GridView. But when I click the button 2nd time, I will append new items to the list.Items are getting added to the list, but these items are not getting populated in the DataGridView. I have tried BindingSource also, this has the same problem as before. I am sure that the DataGridView is not detecting the new list of data.

Can any one help me with this.
Posted

try this
dataGridView1.DataSource = fileDetails.ToArray();
 
Share this answer
 
Comments
Prasaad SJ 26-Jun-14 7:18am    
Vow. I don't know how it works. But it is working good.. Can you explain how it works when you convert your list to Array.
clear and then set the DataSource
C#
grdView.Rows.Clear();
grdView.DataSource=files;
 
Share this answer
 
Comments
Prasaad SJ 25-Jun-14 23:32pm    
"Rows collection cannot be programmatically cleared when the DataGridView control is data-bound to anything else than an IBindingList that supports change notification and allows deletion."

I am getting this error. Seems we cannot manually clear the rows.
DamithSL 26-Jun-14 0:11am    
are you using binding source?
Prasaad SJ 26-Jun-14 7:08am    
If I use the binding source, I m not getting the error but no rows are displayed even if I add new values to the list.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900