C# Datagridview selected row -
i have datagridview have implemented search function. entering characters while datagridview in focus first row of grid characters selected.
i use:
dtgview[index].selected = true; dtgview.firstdisplayedscrollingrowindex = index;
the row gets selected, when press or down arrows navigate or down selected row, datagridview starts row index 0 in datagrid , not newly selected row?
here op's
original code / method
private void dtgview_keyup(object sender, keyeventargs e) { if (e.keyvalue >= 65 && e.keyvalue <= 90 ) { searchstrings += e.keycode; (int = 0; < dtgview.rowcount; i++) { if (dtgview.rows[i].cells[0].value.tostring(). substring(0, searchstrings.length) == searchstrings) { dtgview.clearselection(); dtgview.firstdisplayedscrollingrowindex = i; dtgview.rows[i].selected = true; dtgview.rows[i].cells[0].selected = true; break; } } } }
this key_up event on dtg:
private void dtgview_keyup(object sender, keyeventargs e) { if (e.keyvalue >= 65 && e.keyvalue <= 90 ) { searchstrings += e.keycode; (int = 0; < dtgview.rowcount; i++) { if (dtgview.rows[i].cells[0].value.tostring(). substring(0, searchstrings.length) == searchstrings) { dtgview.clearselection(); dtgview.firstdisplayedscrollingrowindex = i; dtgview.rows[i].selected = true; dtgview.rows[i].cells[0].selected = true; break; } } } }
Comments
Post a Comment