不应该在CellValidated事件中处理。
1. 应该先处理MultiRow的CellEndEdit事件, 在这个事件中判断,如果是从第二列结束的编辑状态,那么就将焦点跳转到第三列。
2. 还需要处理MultiRow的RowValidating事件, 在这个事件中判断,如果第三列的值是空,就Cancel掉,并且将焦点跳转到第三列。
代码如下:
- void g_CellEndEdit(object sender, CellEndEditEventArgs e)
- {
- GcMultiRow g = sender as GcMultiRow;
- if (e.CellIndex == 1)//这里CellIndex是 1,是要判断你刚刚输入完了第二列cell。
- {
- g.CurrentCellPosition = new CellPosition(e.RowIndex, 2);//这里CellIndex是 2,是定位到第三列
- }
- }
- void g_RowValidating(object sender, CellCancelEventArgs e)
- {
- GcMultiRow g = sender as GcMultiRow;
- if (g!= null )
- {
- if (g.GetValue(e.RowIndex, 1)!= null && g.GetValue(e.RowIndex, 2) == null)//这里CellIndex是 2,是判断第三列
- {
- e.Cancel = true;
- g.CurrentCellPosition = new CellPosition(e.RowIndex, 2);//这里CellIndex是 2,是定位到第三列
- }
- }
- }
复制代码 VB代码:
- Private Sub g_CellEndEdit(sender As Object, e As CellEndEditEventArgs)
- Dim g As GcMultiRow = TryCast(sender, GcMultiRow)
- If e.CellIndex = 1 Then
- '这里CellIndex是 1,是要判断你刚刚输入完了第二列cell。
- '这里CellIndex是 2,是定位到第三列
- g.CurrentCellPosition = New CellPosition(e.RowIndex, 2)
- End If
- End Sub
- Private Sub g_RowValidating(sender As Object, e As CellCancelEventArgs)
- Dim g As GcMultiRow = TryCast(sender, GcMultiRow)
- If g IsNot Nothing Then
- If g.GetValue(e.RowIndex, 1) IsNot Nothing AndAlso g.GetValue(e.RowIndex, 2) Is Nothing Then
- '这里CellIndex是 2,是判断第三列
- e.Cancel = True
- '这里CellIndex是 2,是定位到第三列
- g.CurrentCellPosition = New CellPosition(e.RowIndex, 2)
- End If
- End If
- End Sub
复制代码 |