Move the selected row to one row up and make it selected
-
Hi Me with C#.net gridview, I am trying to move the selected row to one row up on uparrow keydown and is working fine but after moving the selected row to one row up still the selected row remains with the previous row, How can I make the selected row as the one which I had moved up so that on the next uparrow key press that row will move up my code is private void dgvQuotationEntry_KeyDown(object sender, KeyEventArgs e) { int Asciival = e.KeyValue; string ID , PRDCode int rowIndex = 0, rowCount; rowIndex = dgvQuotationEntry.CurrentCell.RowIndex; rowCount = dgvQuotationEntry.Rows.Count; if (Asciival == 38) { if (dgvQuotationEntry.CurrentCell != null && rowIndex != 0) { ID = dgvQuotationEntry.CurrentRow.Cells[0].Value.ToString(); PRDCode = dgvQuotationEntry.CurrentRow.Cells[1].Value.ToString(); dgvQuotationEntry.Rows.RemoveAt(rowIndex); dgvQuotationEntry.Rows.Insert(--rowIndex, ID , PRDCode); } } }
Thanks & Regards
-
Hi Me with C#.net gridview, I am trying to move the selected row to one row up on uparrow keydown and is working fine but after moving the selected row to one row up still the selected row remains with the previous row, How can I make the selected row as the one which I had moved up so that on the next uparrow key press that row will move up my code is private void dgvQuotationEntry_KeyDown(object sender, KeyEventArgs e) { int Asciival = e.KeyValue; string ID , PRDCode int rowIndex = 0, rowCount; rowIndex = dgvQuotationEntry.CurrentCell.RowIndex; rowCount = dgvQuotationEntry.Rows.Count; if (Asciival == 38) { if (dgvQuotationEntry.CurrentCell != null && rowIndex != 0) { ID = dgvQuotationEntry.CurrentRow.Cells[0].Value.ToString(); PRDCode = dgvQuotationEntry.CurrentRow.Cells[1].Value.ToString(); dgvQuotationEntry.Rows.RemoveAt(rowIndex); dgvQuotationEntry.Rows.Insert(--rowIndex, ID , PRDCode); } } }
Thanks & Regards
-
This should work dgvQuotationEntry.Rows.Insert(--rowIndex, ID ,PRDCoded); gvQuotationEntry.SelectedIndex=rowIndex;
but for datagridview there is not a property like SelectedIndex
Thanks & Regards