- 积分
- 352
- 在线时间
- 183 小时
- 主题
- 22
- 注册时间
- 2016-9-10
- 帖子
- 142
- 最后登录
- 2022-9-21
- 帖子
- 142
- 软币
- 1717
- 在线时间
- 183 小时
- 注册时间
- 2016-9-10
|
先创建一个GridControl,在创建一个GridView视图,再传入数据
GridControl CreateGrid(List<marketinformation> pagemodel)
{
GridControl grid = new GridControl(); ;
GridView view = new GridView();
grid.ViewCollection.Add(view);
grid.MainView = view;
view.GridControl = grid;
foreach (GridColumn column in gridView2.Columns)
{
DevExpress.XtraGrid.Columns.GridColumn gridColumnNumber = view.Columns.AddVisible(column.FieldName.ToString());
gridColumnNumber.Caption = column.Caption.ToString();
gridColumnNumber.FieldName = column.FieldName.ToString();
}
grid.DataSource = pagemodel;
this.Controls.Add(grid);//重要
grid.ForceInitialize();//重要
BestColumns(view);
view.OptionsPrint.AutoWidth = false;
return grid; }
然后数据分页创建
IPrintable[] arr(List<marketinformation> data)
{
List<IPrintable> Printable=new List<IPrintable>();
int PageIndex=0;
int PageSize=50000;
int CurrentIndex=0;
int TotalCount=data.Count;
for(PageIndex=0;CurrentIndex<TotalCount;PageIndex++)
{
var PageData = data.Skip(PageIndex*PageSize).Take(PageSize).ToList();
Printable.Add(CreateGrid(PageData));
CurrentIndex=(PageIndex+1)*PageSize;
}
return Printable.ToArray(); }
最后数据多的时候自动列宽或假死,可以循环固定列宽,也可以写字段名
void BestColumns(GridView view)
{
if (chkeds.Checked)
{
view.OptionsView.ColumnAutoWidth = false;
foreach (GridColumn column in view.Columns)
{
if (column.Visible)
{
switch (column.FieldName.ToString())
{
case "caccount":
view.Columns["caccount"].Width = 150;
break;
case "cunitname":
view.Columns["cunitname"].Width = 300;
break;
case "ddate":
view.Columns["ddate"].Width = 150;
break;
case "cemskind":
view.Columns["cemskind"].Width = 100;
break;
case "cnum":
view.Columns["cnum"].Width = 150;
break;
case "dsysdate":
view.Columns["dsysdate"].Width = 150;
break;
default:
view.Columns[column.FieldName].Width = 100;
break;
}
}
}
}
else
{
view.OptionsView.ColumnAutoWidth = true;
foreach (GridColumn column in view.Columns)
{
if (column.Visible)
{
view.Columns[column.FieldName].Width = 75;
}
}
} }
|
评分
-
查看全部评分
|