如下的代码实现,有两个问题:
1.刚刚编辑的数据,回车跳到下一行后失效(会变为旧的数据)
2.若当前为第n行,调试时会跳到n+1行并是单元格编辑状态,实现了想要的效果;但非调试时会跳到第n+2行,单元格也不是编辑状态
请帮忙看下
- //捕捉键盘按下事件
- private void _processFlowFlexGrid_PreviewKeyDown(object sender, KeyEventArgs e)
- {
- try
- {
- var grid = sender as C1FlexGrid;
- if (e.Key != Key.Enter || grid == null) return;
- //当前单元格的坐标位置
- int row = grid.Selection.Row;
- int col = grid.Selection.Column;
- //提交本次编辑
- grid.FinishEditing(true);
- //参数校验
- bool checkParamResult = true;
- var model = (FlowModel)grid.SelectedItem;
- if (null != model && !string.IsNullOrEmpty(model.ParamValue))
- {
- checkParamResult = CheckParam(model);
- }
- if (checkParamResult) //通过
- {
- e.Handled = true;
- //下一行的序号
- int newRowIndex = row + 1;
- newRowIndex = grid.Rows.Count > newRowIndex ? newRowIndex : row;
- //滚动到将要编辑的下个单元格
- grid.ScrollIntoView(newRowIndex, col);
- grid.StartEditing(true, newRowIndex, col);
- }
- else //未通过
- {
- e.Handled = true;
- grid.StartEditing(true, row, col);
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
复制代码 |