Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Move the selected row to one row up and make it selected

Move the selected row to one row up and make it selected

Scheduled Pinned Locked Moved C#
csharpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anu Palavila
    wrote on last edited by
    #1

    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

    W 1 Reply Last reply
    0
    • A Anu Palavila

      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

      W Offline
      W Offline
      WvdW
      wrote on last edited by
      #2

      This should work dgvQuotationEntry.Rows.Insert(--rowIndex, ID ,PRDCoded); gvQuotationEntry.SelectedIndex=rowIndex;

      A 1 Reply Last reply
      0
      • W WvdW

        This should work dgvQuotationEntry.Rows.Insert(--rowIndex, ID ,PRDCoded); gvQuotationEntry.SelectedIndex=rowIndex;

        A Offline
        A Offline
        Anu Palavila
        wrote on last edited by
        #3

        but for datagridview there is not a property like SelectedIndex

        Thanks & Regards

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups