gridcontrol使用
2个回答
展开全部
private void mnuLoad_Click(object sender, System.EventArgs e)
{
// TODO: Load Customers
Database db = null;
db = DatabaseFactory.CreateDatabase();
DataSet ds = db.ExecuteDataSet(
CommandType.Text,
"SELECT ID,Name,Age From UserInfo");
gridControl1.DataSource = ds.Tables[0];
//设置成一次选择一行,并且不能被编辑
this.gridView1.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
this.gridView1.OptionsBehavior.Editable = false;
this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
//设置列的标题
gridView1.Columns[0].Caption = "编号";
gridView1.Columns[1].Caption = "名称";
gridView1.Columns[2].Caption = "年龄";
//设置列的名称,便于进行分组和Foot的统计等信息显示
gridView1.Columns[0].Name = "ID";
gridView1.Columns[1].Name = "Name";
gridView1.Columns[2].Name = "Age";
//增加一个Group列进行分组
this.gridView1.GroupSummary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] {
new DevExpress.XtraGrid.GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Count, "ID", null, "(Count={0})")});
//增加一个Group列进行分组
this.gridView1.GroupSummary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] {
new DevExpress.XtraGrid.GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Max , "Age", null, "(Max={0})")});
//设置并制作Foot下面的统计信息
this.gridView1.GroupFooterShowMode = DevExpress.XtraGrid.Views.Grid.GroupFooterShowMode.VisibleAlways;
this.gridView1.OptionsView.ShowFooter = true;
gridView1.Columns[2].SummaryItem.DisplayFormat = "(Age={0})";
gridView1.Columns[2].SummaryItem.FieldName = "Age";
gridView1.Columns[2].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
}
//设置成cardview格式
private void menuItem2_Click(object sender, EventArgs e)
{
gridControl1.MainView = this.cardView1;
}
//设置成GridView格式
private void menuItem4_Click(object sender, EventArgs e)
{
gridControl1.MainView = this.gridView1 ;
}
自己模仿着写把
{
// TODO: Load Customers
Database db = null;
db = DatabaseFactory.CreateDatabase();
DataSet ds = db.ExecuteDataSet(
CommandType.Text,
"SELECT ID,Name,Age From UserInfo");
gridControl1.DataSource = ds.Tables[0];
//设置成一次选择一行,并且不能被编辑
this.gridView1.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
this.gridView1.OptionsBehavior.Editable = false;
this.gridView1.OptionsSelection.EnableAppearanceFocusedCell = false;
//设置列的标题
gridView1.Columns[0].Caption = "编号";
gridView1.Columns[1].Caption = "名称";
gridView1.Columns[2].Caption = "年龄";
//设置列的名称,便于进行分组和Foot的统计等信息显示
gridView1.Columns[0].Name = "ID";
gridView1.Columns[1].Name = "Name";
gridView1.Columns[2].Name = "Age";
//增加一个Group列进行分组
this.gridView1.GroupSummary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] {
new DevExpress.XtraGrid.GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Count, "ID", null, "(Count={0})")});
//增加一个Group列进行分组
this.gridView1.GroupSummary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] {
new DevExpress.XtraGrid.GridGroupSummaryItem(DevExpress.Data.SummaryItemType.Max , "Age", null, "(Max={0})")});
//设置并制作Foot下面的统计信息
this.gridView1.GroupFooterShowMode = DevExpress.XtraGrid.Views.Grid.GroupFooterShowMode.VisibleAlways;
this.gridView1.OptionsView.ShowFooter = true;
gridView1.Columns[2].SummaryItem.DisplayFormat = "(Age={0})";
gridView1.Columns[2].SummaryItem.FieldName = "Age";
gridView1.Columns[2].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum;
}
//设置成cardview格式
private void menuItem2_Click(object sender, EventArgs e)
{
gridControl1.MainView = this.cardView1;
}
//设置成GridView格式
private void menuItem4_Click(object sender, EventArgs e)
{
gridControl1.MainView = this.gridView1 ;
}
自己模仿着写把
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询