》另外,能否处理成如果单元格有内容的就向右移,如果没内容的就停留在该单元格
这个,需要自定义一个Action,实现我们的IAction接口,然后把自定义的Action付给MultiRow的Enter键,代码如下。
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- //删除原有Enter键对应的Action
- this.gcMultiRow1.ShortcutKeyManager.Unregister(Keys.Enter);
- //给Enter键指定自定义的Action
- this.gcMultiRow1.ShortcutKeyManager.Register(new MyAction(), Keys.Enter);
- }
- }
-
- //自定义一个Action
- public class MyAction : IAction
- {
- #region IAction 成员
- public bool CanExecute(GcMultiRow target)
- {
- return true;
- }
- public string DisplayName
- {
- get { return "MyAction"; }
- }
- public void Execute(GcMultiRow target)
- {
- //判断当前的Cell是否有内容,这里只做一个简单的判断,具体的判断依赖于你的业务逻辑
- if (target.CurrentCell.EditedFormattedValue == null)
- {
- //do nothing
- }
- else
- {
- // 跳到下一个Cell,如果要在行内循环,或者跳到下一行,需要自己再写一点逻辑来指定CurrentCellPosition的新位置,这里只简单演示一下。
- int rowIndex = target.CurrentCell.RowIndex;
- int cellIndex = target.CurrentCell.TabIndex;
- target.CurrentCellPosition = new CellPosition(rowIndex, cellIndex + 1);
- }
- }
- #endregion
- }
- }
复制代码 |