您的位置:首页 > 编程语言 > C#

C# 对于GridControl 动态加载动态生成的GridView

2017-05-25 16:40 417 查看
对于GridView来说,在实际应用中经常可能会需要动态生成列,

今天试着写了一下,大家看看即可,第一次写博客。。。。

>

private void NewGridView(List list) //

{

var gdv = new DevExpress.XtraGrid.Views.Grid.GridView();//

gdv.OptionsView.ShowGroupPanel = false;

string[] temp = new Apple().GetNames(); //根据传入的数据类Apple的属性来动态生成GridView的列
for(int i = 0;i<= temp.Length;i++)
{
var col  = new DevExpress.XtraGrid.Columns.GridColumn();
col .Caption = ass[i];
col.FieldName = ass[i];
col.Visible = true;
col.VisibleIndex = i;
gdv.Columns.Add(col);
}
this.gridControl1.MainView = gdv;//将gdv设置为MainView
this.gridControl1.Datasource = list; //加载数据


}

public class Apple

{

private int size;

public int Size

{

get;set;

}

private int brand;

public int Brand

{

get;set;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  gridview c#