将DataGridView绑定到Windows应用程序中的列表 [英] Binding DataGridView to list in Windows applicatoin

查看:128
本文介绍了将DataGridView绑定到Windows应用程序中的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试图用DataGridView数据源绑定一个List





Hi,
I m trying to bind a List with DataGridView Datasource


grdView.DataSource=files;
where files is the List





我在按钮事件中分配上述内容。我在同一个Button事件中将项添加到列表中。这在我第一次调用Button事件时工作正常。项目将在GridView上填充。但是当我第二次单击该按钮时,我会将新项目附加到list.Items被添加到列表中,但这些项目不会在DataGridView中填充。我也尝试过BindingSource,这和以前一样有问题。我确信DataGridView没有检测到新的数据列表。



任何人都可以帮我这个。



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.

推荐答案

试试这个

dataGridView1.DataSource = fileDetails.ToArray();
try this
dataGridView1.DataSource = fileDetails.ToArray();


clear然后设置DataSource

clear and then set the DataSource
grdView.Rows.Clear();
grdView.DataSource=files;


这篇关于将DataGridView绑定到Windows应用程序中的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆