相关类介绍:
1.LSGOUIGridEntity 用于配置FlexCell表格各种参数的实体
有已下三种便捷的方法,均返回已经配置好参数的LSGOUIGridEntity 类的实体
GetNormalGridEntity() 得到普通类型的MisUIGridEntity.
GetDark_LightBlueGridEntity() 得到深蓝-浅蓝格调的GridEntity.
GetYellow_WhiteGridEntity() 得到黄-白格调的GridEntity.
示例:LSGOUIGridEntity gridEntity = (new LSGOUIGridEntity()).GetYellow_WhiteGridEntity();
2.LSGOUIGrid FlexCell表格控件类,提供初始化,操纵表格的各种静态方法
Init:初始化FlexCell表格控件的属性及样式
public static void Init(Grid Grid, LSGOUIGridEntity GridEntity)
示例:LSGOUIGrid.Init(grid, gridEntity);
InitHeader 初始化表格的列名(通过字符串链表/ILSGODataFieldCollection)
public static void InitHeader(Grid Grid, List<string> FieldList)
public static void InitHeader(Grid Grid, ILSGODataFieldCollection FieldCollection)
示例:
List<string> pListStr = new List<string> { "版本属性", "版本信息" }; //创建字符串链表
LSGOUIGrid.InitHeader(grid, pListStr); //初始化表格的列名
将信息填入FlexCell表格中
FillDataToGrid()的各种重载方法
public static void InsertDataToGrid(List<string> valueList, Grid Grid) //自定义方法
示例:LSGOUIGrid.InsertDataToGrid(new List<string> { "用户名", "" }, grid_Verson);
使用方法示例:
整体思路分三或四步:
实例化 LSGOUIGridEntity
调用LSGOUIGrid.Init()初始化表格
(选)调用LSGOUIGrid.InitHeader()初始化列名
填充内容FillDataToGrid()/InsertDataToGrid()
注:示例1使用LSGOUIGrid.InitHeader()初始化列名,使用InsertDataToGrid()自定义插入数据。
示例2使用FillDataToGrid()方法,通过LSGODataFieldCollection,和LSGODataRowCollection来填充表格内容。初始化列名工作由FillDataToGrid()方法完成
示例1:
/// <summary>
/// 初始化版本信息表格
/// </summary>
/// <param name="grid"></param>
private void InitGrid_Verson(Grid grid)
{
LSGOUIGridEntity gridEntity = (new LSGOUIGridEntity()).GetYellow_WhiteGridEntity();
LSGOUIGrid.Init(grid, gridEntity);
grid.ExtendLastCol = true; //自动延长最后一列
List<string> pListStr = new List<string> { "版本属性", "版本信息" };
LSGOUIGrid.InitHeader(grid, pListStr);
LSGOUIGrid.InsertDataToGrid(new List<string> { "用户名", "" }, grid_Verson);
LSGOUIGrid.InsertDataToGrid(new List<string> { "版本名", "" }, grid_Verson);
LSGOUIGrid.InsertDataToGrid(new List<string> { "父版本名", "" }, grid_Verson);
LSGOUIGrid.InsertDataToGrid(new List<string> { "创建时间", "" }, grid_Verson);
LSGOUIGrid.InsertDataToGrid(new List<string> { "最后修改时间", "" }, grid_Verson);
LSGOUIGrid.InsertDataToGrid(new List<string> { "版本描述", "" }, grid_Verson);
grid.Column(0).AutoFit();
}
示例2:
在学生信息管理系统中,查询学生表中,学号为“Sno”的学生的信息
//初始化
LSGOUIGridEntity gridEntity = (new LSGOUIGridEntity()).GetYellow_WhiteGridEntity();
LSGOUIGrid.Init(grid1, gridEntity);
//读取数据
ILSGOSearchFilter pQueryFilter = new LSGOSearchFilter();
pQueryFilter.WhereClause = " Sno= '" + Sno + "'";
rowCollection = new LSGOMisDbComFun(MisDBType.MainDB).GetRowCollectionFromMain(
LSGOMisSystemProperty.ProPrefix + "Student", pQueryFilter);
ILSGODataTable table =
(new LSGOMisDbComFun(MisDBType.MainDB)).GetTableFromMain(LSGOMisSystemProperty.ProPrefix + "Student");
//填充数据
LSGOUIGrid.FillDataToGrid("错误", table.FieldCollection, rowCollection, grid1);
//输出为Excel表格和HTML文档
LSGOUIGrid.ExportToHTML("D:\\学生信息管理系统\\StudentManagementSystem\\bin\\Debug\\aaa.html", grid1);
LSGOUIGrid.ExportToExcel("D:\\学生信息管理系统\\StudentManagementSystem\\bin\\Debug\\aaa.xls", true,true, grid1);
示例2运行结果:
示例3:
列标题会默认命名为数据库中的字段名,若不满意,可调用InitHeader()自定义列标题
string sql =
"select StudentCourse.Cno,Cname,Cpno,Ccredit,Cteacher from Course,StudentCourse where StudentCourse.Cno=Course.Cno and Sno='" + Sno + "'";
DataSet dataset = new LSGOMisDbComFun(MisDBType.MainDB).GetDataSetFromMain(sql);
LSGOUIGrid.FillDataToGrid("数据导入失败", dataset, 0, grid_HasSelectCourse);
//重命名列表题
List<string> pListStr = new List<string> { "课程号", "课程名", "先修课", "学分", "任课教师" };
LSGOUIGrid.InitHeader(grid_HasSelectCourse, pListStr);
常用属性
AutoRedraw 自动重绘
ExtendLastCol 自动延长最后一列
Rows、Cols 行数,列数。
可用于清空功能:如grid.Rows = 1;可将表格列标题以外的行清空
Locked 只读
特别的,如果需要对表格中的某些元素/行/列设置只读,其余不设,偷懒的方法是不行的。需要对表格整体设置非只读,然后对只读元素依次设置,例如:
//取消教师评价列的只读设置
grid_StudentScore.Locked = false;
grid_StudentScore.Column(0).Locked = true ;
grid_StudentScore.Column(1).Locked = true;
grid_StudentScore.Column(2).Locked = true;
grid_StudentScore.Column(3).Locked = true;
grid_StudentScore.Column(4).Locked = true;
本文出自 “随煜而安” 博客,转载请与作者联系!