gridcontrol使用

 我来答
匿名用户
2013-08-12
展开全部
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 ;

}
自己模仿着写把
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式