原创:C#源码 GridMovetor按回车自动跳到下一列或自动新增记录(www.csframework.com)
作者:C/S框架网|www.cscode.ne  发布日期:2020/11/16 15:51:22
  原创:C#源码 GridMovetor按回车自动跳到下一列或自动新增记录(www.csframework.com)


应用场景:


为了提高用户体验,在明细表格内按回车键,要自动跳转到下一个可编辑列, 若是最后一行的最后一列, 自动新增一条记录。


贴图图片-GridMovetor



使用方法:绑定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



测试程序的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




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





C/S框架网|原创精神.创造价值.打造精品

扫一扫加微信
C/S框架网作者微信 C/S框架网|原创作品.质量保障.竭诚为您服务



点击下载附件 (VIP会员下载) 点击下载附件 (如下载失败,请邮件通知我们寄回给您,或QQ:23404761留言.)
上一篇 下一篇