日期:2014-05-18  浏览次数:20727 次

简单的dataGridView1列切换焦点问题
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  {
   
  //dataGridView1.CurrentCell = dataGridView1[4, 0];

  if (dataGridView1.CurrentCell.ColumnIndex == 1)
  {
  dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[4];
  }
  else if (dataGridView1.CurrentCell.ColumnIndex==4)
  {
  dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1];
  }
  }
为什么dataGridView1列切换焦点时,不能切换到同一行?
为什么我这样写,每次按enter键的时候都是切换到下一行指定的列,而不是同一行的那列?
请大虾们赐教、帮忙。

------解决方案--------------------
参考这篇文章
DataGridView按回车换列-同行下一单元格
------解决方案--------------------
这个功能我也实现过,最后的解决办法是,重写了DataGridView控件的KeyDown事件,当控件捕获到Enter时,让控件响应Tab键