下列代码演示了通过 GridControl.ProcessGridKey 事件处理程序处理自定义键击事件。 此处理程序在网格视图的行间移动焦点。 当用户按下空格键时把焦点向前移动,当用户按下退格键时把焦点向后移动。

C#CopyCode image复制代码
private void gridControl1_ProcessGridKey(object sender, 
  System.Windows.Forms.KeyEventArgs e) {
    if (gridView1.IsGroupRow(gridView1.FocusedRowHandle)) return;
    if (e.KeyCode == Keys.Space) {
        if (gridView1.FocusedRowHandle < gridView1.DataRowCount - 1) {
            gridView1.FocusedRowHandle += 1;
            e.Handled = true;
        }
    }
    if (e.KeyCode == Keys.Back) {
        if (gridView1.FocusedRowHandle > 0) {
            gridView1.FocusedRowHandle -= 1;
            e.Handled = true;
        }
    }
}
Visual BasicCopyCode image复制代码
Private Sub GridControl1_ProcessGridKey(ByVal sender As Object, _
  ByVal e As System.Windows.Forms.KeyEventArgs) _
  Handles GridControl1.ProcessGridKey
    If GridView1.IsGroupRow(GridView1.FocusedRowHandle) Then Exit Sub
    If e.KeyCode = Keys.Space Then
        If GridView1.FocusedRowHandle < GridView1.DataRowCount - 1 Then
            GridView1.FocusedRowHandle += 1
            e.Handled = True
        End If
    End If
    If e.KeyCode = Keys.Back Then
        If GridView1.FocusedRowHandle > 0 Then
            GridView1.FocusedRowHandle -= 1
            e.Handled = True
        End If
    End If
End Sub