当前所知有两种方式
当前程序使用第一种,但数据源数据增加时需要更新gridview.freshdata();
第二种方式似乎不用,以前用过,懒得测试了
方式一
1:初始化一个数据源集合对象
List<Student> studentl= new List<Student>();
2:绑定数据源
gridControl1.DataSource = studentl;
3:给studentl 赋值后更新gridview
Student student =new Student{ name="xiaoli"};
studentl.Add(student);
//gridControl1.Refresh();
gridView1.RefreshData(); //不刷新不更新显示
方式二 数据源与控件中间BindingSource
BindingList<FormItem> itemsBindingList = new BindingList<FormItem>(); List<FormItem> itemsList = new List<FormItem>(); BindingSource bs = new BindingSource(); private void simpleButton1_Click(object sender, EventArgs e) { for (int i = 0; i < 10; i++) { FormItem fi = new FormItem(); fi.ItemKey = i.ToString(); fi.Name = Guid.NewGuid().ToString(); if (i % 2 == 0) { fi.Enable = true; } else { fi.Enable = false; } itemsBindingList.Add(fi); itemsList.Add(fi); bs.Add(fi); } //this.gridControl1.DataSource = itemsBindingList; //this.gridControl1.DataSource = itemsList; this.gridControl1.DataSource = bs; }