2

我只想在特定列上设置标签顺序。例如我有 2 列(ID 和名称)。所以选项卡仅反映在“名称”列上。当我按下制表符时,它会垂直转到同一列中的下一行。

4

2 回答 2

4

我认为您必须重写该ProcessDataGridViewKey方法来捕获Tab密钥并自己选择单元格,如下所示:

public class CustomDataGridView : DataGridView
{    
    //This contains all the column indices in which the tab will be switched vertically. For your case, the initial index is 1 (the second column): VerticalTabColumnIndices.Add(1);
    public List<int> VerticalTabColumnIndices = new List<int>();    
    protected override bool ProcessDataGridViewKey(KeyEventArgs e)
    {
        if (e.KeyCode == Keys.Tab&&VerticalTabColumnIndices.Contains(CurrentCell.ColumnIndex))
        {
            int i = (CurrentCell.RowIndex + 1) % Rows.Count;
            CurrentCell = Rows[i].Cells[CurrentCell.ColumnIndex];
            return true;//Suppress the default behaviour which switches to the next cell. 
        }
        return base.ProcessDataGridViewKey(e);
    }
}
//or simply you can handle the Tab key in a KeyDown event handler
private void KeyDownHandler(object sender, KeyEventArgs e){
  if(e.KeyCode == Keys.Tab){
     e.Handled = true;
     //remaining code...
     //.....
  }
}
//in case you are not familiar with event subscribing
yourDataGridView.KeyDown += KeyDownHandler;
于 2013-07-22T16:48:09.013 回答
0

dataridview 中的列没有选项卡顺序
1)您可以覆盖 keydown 事件以处理选项卡。
2) 另一种简单的方法是按上、下、左、右键在数据网格视图中导航。

于 2015-07-21T11:04:21.990 回答