原创:C#源码 GridMovetor按回车自动跳到下一列或自动新增记录(www.csframework.com)
原创:C#源码 GridMovetor按回车自动跳到下一列或自动新增记录(www.csframework.com)
3个GridControl组件共用一个EmbeddedNavigator_ButtonClick事件
扫一扫加微信
应用场景:
为了提高用户体验,在明细表格内按回车键,要自动跳转到下一个可编辑列, 若是最后一行的最后一列, 自动新增一条记录。
使用方法:绑定GridView的KeyDown事件
C# Code:
private void gridView1_KeyDown(object sender, KeyEventArgs e)
{
//表格按回车键,自动移动到下一个可编辑列, 如果是最后一列, 自动新增一条记录
CSFrameworkV5.Library.CommonClass.GridMovetor.OnGridViewKeyDown(gridView1, e);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
private void gridView1_KeyDown(object sender, KeyEventArgs e)
{
//表格按回车键,自动移动到下一个可编辑列, 如果是最后一列, 自动新增一条记录
CSFrameworkV5.Library.CommonClass.GridMovetor.OnGridViewKeyDown(gridView1, e);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
测试程序的Form.Load事件
C# Code:
private void Form1_Load(object sender, EventArgs e)
{
gridControl1.DataSource = GridMovetorTester.DemoData.Customers;
gridControl2.DataSource = GridMovetorTester.DemoData.Customers;
gridControl3.DataSource = GridMovetorTester.DemoData.Customers;
gridControl1.EmbeddedNavigator.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(this.gridControl1_EmbeddedNavigator_ButtonClick);
gridControl2.EmbeddedNavigator.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(this.gridControl1_EmbeddedNavigator_ButtonClick);
gridControl3.EmbeddedNavigator.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(this.gridControl1_EmbeddedNavigator_ButtonClick);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
{
gridControl1.DataSource = GridMovetorTester.DemoData.Customers;
gridControl2.DataSource = GridMovetorTester.DemoData.Customers;
gridControl3.DataSource = GridMovetorTester.DemoData.Customers;
gridControl1.EmbeddedNavigator.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(this.gridControl1_EmbeddedNavigator_ButtonClick);
gridControl2.EmbeddedNavigator.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(this.gridControl1_EmbeddedNavigator_ButtonClick);
gridControl3.EmbeddedNavigator.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(this.gridControl1_EmbeddedNavigator_ButtonClick);
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
3个GridControl组件共用一个EmbeddedNavigator_ButtonClick事件
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
/// 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框架网