DevExpress GridControl组件的EmbeddedNavigator属性添加用户自定义按钮
DevExpress GridControl组件的EmbeddedNavigator属性添加用户自定义按钮
、
5. 给自定义按钮绑定Click事件:
扫一扫加微信
如何在表格中添加用户自定义按钮?如下图红圈标识的添加【+】按钮:
操作步骤:
1. 隐藏默认的按钮。
展开GridControl.EmbeddedNavigator.Buttons属性,隐藏以下7个默认按钮:
Append, CancelEdit, Edit, EndEdit, NextPage, PrevPage, Remove。
设置属性:Visible=false, 即可隐藏。
2. 拖放一个ImageList组件到界面中, 添加图标:
3. 绑定ImageList组件。
展开GridControl.EmbeddedNavigator.Buttons属性,选择ImageList:
4. 添加自定义按钮。
展开GridControl.EmbeddedNavigator.Buttons属性,
打开CustomButtons设计器, 点Add按钮,添加自定义按钮,并选择ImageIndex:
、
5. 给自定义按钮绑定Click事件:
C# Code:
C# Code:
private void Form1_Load(object sender, EventArgs e)
{
gridControl1.DataSource = GridMovetorTester.DemoData.Customers;
gridControl1.EmbeddedNavigator.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(this.gridControl1_EmbeddedNavigator_ButtonClick);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
private void Form1_Load(object sender, EventArgs e)
{
gridControl1.DataSource = GridMovetorTester.DemoData.Customers;
gridControl1.EmbeddedNavigator.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(this.gridControl1_EmbeddedNavigator_ButtonClick);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
C# Code:
/// <summary>
/// 3个表格组件共用1个EmbeddedNavigator_ButtonClick事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gridControl1_EmbeddedNavigator_ButtonClick(object sender, DevExpress.XtraEditors.NavigatorButtonClickEventArgs e)
{
ControlNavigator nav = sender as ControlNavigator;
//获取GridControl组件的实例
GridControl gc = nav.Parent as GridControl;
//数据源添加一条记录
DataTable dt = gc.DataSource as DataTable;
dt.Rows.Add(dt.NewRow());
//获取GridView的实例, 调用MoveLast方法
(gc.Views[0] as GridView).MoveLast();
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
/// <summary>
/// 3个表格组件共用1个EmbeddedNavigator_ButtonClick事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void gridControl1_EmbeddedNavigator_ButtonClick(object sender, DevExpress.XtraEditors.NavigatorButtonClickEventArgs e)
{
ControlNavigator nav = sender as ControlNavigator;
//获取GridControl组件的实例
GridControl gc = nav.Parent as GridControl;
//数据源添加一条记录
DataTable dt = gc.DataSource as DataTable;
dt.Rows.Add(dt.NewRow());
//获取GridView的实例, 调用MoveLast方法
(gc.Views[0] as GridView).MoveLast();
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
扫一扫加微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网