void DefineView() { LB = new MyListBox(listBox1, "select * from DiaryGroups order by GroupOrder", "GroupName", "GroupID", Global.con); GV = new MyGridViewA(dataGridView1); try { LB.SelectedIndex = 0; } catch { LB.SelectedIndex = -1; } GV.SetDB(Global.con, "DiaryRecords"); GV.ColumnWidths = new int[] { 0, 0, 115, 205 }; GV.RowHeight = 30; GV.SetStyle("Cambria", 14, FontStyle.Bold); GV.QueryFields = "RecordID,GroupID,DateOfRecord as 记录日期,Content as 日记内容"; GV.OrderBy("DateOfRecord desc,RecordID desc"); GV.PerPage = INI.GetPerPage(); GV.NowPage = 1; GV.KeyColumn = "RecordID"; ShowData(); }
void GVLoadA() { GVA = new MyGridViewA(dataGridView1); //GVA.AlignCenter = true;//内容对齐方式(默认靠左),仅在SetStyle之前设置有效 //GVA.CanEdit = true;//是否可编辑(默认不可编辑) //GVA.CanResizeColumns = false;//是否可调整列宽(默认可调整,自动适应时设置无效) //GVA.CanResizeRows = true;//是否可调整行高(默认不可调整,自动适应时设置无效) GVA.SetStyle();//设定样式 //GVA.SetStyle("宋体",16f,FontStyle.Bold);//设定样式2 GVA.SetDB(conA, "Employees");//设置数据库 //GVA.ColumnWidths = new int[] { 50, 90, 80 };//列宽(默认自动适应) //GVA.RowHeight = 35;//行高(默认自动适应) //GVA.SetColumnSortModes(new bool[] { true, false, false });//列排序功能(默认禁用) //GVA.RowColor = Color.AntiqueWhite;//行色(默认白色,绑定数据时无效) GVA.QueryFields = "EmployeeID as ID,LastName+FirstName as 姓名,TitleOfCourtesy as 尊称"; //输出列控制 //GVA.QueryFields = "BirthDate";//输出列控制 GVA.OrderBy("EmployeeID asc"); //排序字段与排序方式(默认按首列升序) //GVA.Where("EmployeeID>2");//条件限制(默认无条件限制) //GVA.ClearWhere();//清除条件限制 //GVA.ClearOrderBy();//重置排序方式 //GVA.UseSpecialSQL("select EmployeeID as ID from Employees");//自定义SQL语句 //GVA.AbandonSpecialSQL();//不使用自编SQL语句并清除掉 //分组必赋值以下3个变量,否则报错(若PerPage为0或未赋值则不分页) GVA.PerPage = 5; //每页显示条数 GVA.NowPage = 1; //当前页码 GVA.KeyColumn = "EmployeeID"; //主键列 //*/ GVA.ShowData(); //代码生成数据 /*/ * GVA.BindData();//控件绑定数据 * //*/ Console.WriteLine("载入条数:" + GVA.CountRows);//获取总行数(显示数据后更新) numericUpDown1.Maximum = (decimal)GVA.TotalPages; }