Winform program C# control tab and enter button jump mode horizontal and vertical jump datagirdview any way

Rewrite: override bool ProcessCmdKey this method. Every time you press the key, you will enter this method and
write some comments. You can change the others according to your needs.
///
/// Control the datagirdview grid to jump to enter or tab
///
///
///
///
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{ //Add this judgment so as not to press the button on the column will report an error if (keyData == Keys.Enter && this.dataGridView1.CurrentCell != null) { //return true; / /This return is used to skip the default Enter event effect //return base.ProcessCmdKey(ref msg, Keys.Tab); int columnC = dataGridView1.CurrentCell.ColumnIndex; if(columnC==6) { //If it is the last line No operation if (dataGridView1.CurrentCell.RowIndex + 1 == dataGridView1.Rows.Count) { return true;












}
//Set the corresponding column, which is equivalent to pressing Enter to select the next cell in the same row. The effect is the same as the tab key
dataGridView1.CurrentCell=dataGridView1[2,(dataGridView1.CurrentCell.RowIndex+1)];
}
//Other columns are normal Operation
if (columnC == 7)
{ return base.ProcessCmdKey(ref msg, keyData); } else { SendKeys.Send("{Tab}"); return true; } } //return false; return base.ProcessCmdKey(ref msg, keyData); }










Guess you like

Origin blog.csdn.net/hello_mr_anan/article/details/84535716