indexing - C#: get row back in datagridview (shift+tab) -
i programmatically jump next row pressing tab button. if want jump back, use tab + shift key. if tab + shift pressed, rowcount gets reduced two. when want go last row, index jumps first control, has tab index of 0. whats problem @ last row?
private void datagridview1_keydown(object sender, keyeventargs e) { if (e.keycode == keys.tab) { int row = datagridview1.currentcell.rowindex; row++; if (row > datagridview1.rowcount - 1) { menustrip1.select(); datensatztoolstripmenuitem.select(); datagridview1.currentcell = datagridview1[0, 0]; } else datagridview1.currentcell = datagridview1[0, row]; e.handled = true; } if (e.modifiers == keys.shift && e.keycode == keys.tab) { int row = datagridview1.currentcell.rowindex; row -= 2; if (row < 0) { menustrip1.select(); datensatztoolstripmenuitem.select(); datagridview1.currentcell = datagridview1[0, 0]; } else datagridview1.currentcell = datagridview1[0, row]; e.handled = true; } }
the problem having because both conditions in code met when shift+tab pressed.
the following code works fine on machine.
private void datagridview1_keydown(object sender, keyeventargs e) { if (e.keycode == keys.tab) { if (e.modifiers != keys.shift) { int row = datagridview1.currentcell.rowindex; row++; if (row > datagridview1.rowcount - 1) { menustrip1.select(); datensatztoolstripmenuitem.select(); datagridview1.currentcell = datagridview1[0, 0]; } else { datagridview1.currentcell = datagridview1[0, row]; } e.handled = true; } else { int row = datagridview1.currentcell.rowindex; row -= 1; if (row < 0) { menustrip1.select(); datensatztoolstripmenuitem.select(); datagridview1.currentcell = datagridview1[0, 0]; } else { datagridview1.currentcell = datagridview1[0, row]; } e.handled = true; } } }
Comments
Post a Comment