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. I want to get row index of datagridview

I want to get row index of datagridview

Scheduled Pinned Locked Moved C#
database
4 Posts 4 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.
  • M Offline
    M Offline
    M Riaz Bashir
    wrote on last edited by
    #1

    Hi everyone, I am working in button click event and i want to get row index of selected row. Kindly let me kknow. Thank you in advance (Riaz)

    W M L 3 Replies Last reply
    0
    • M M Riaz Bashir

      Hi everyone, I am working in button click event and i want to get row index of selected row. Kindly let me kknow. Thank you in advance (Riaz)

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

      Wouldn't it be a whole lot faster to have a look at DataGridView's documentation. :sigh: It's well documented: DataGridView.SelectedRows Property[^]

      The need to optimize rises from a bad design.My articles[^]

      1 Reply Last reply
      0
      • M M Riaz Bashir

        Hi everyone, I am working in button click event and i want to get row index of selected row. Kindly let me kknow. Thank you in advance (Riaz)

        M Offline
        M Offline
        MadArtSoft
        wrote on last edited by
        #3

        YourDataGrid.SelectedRows[0].Index First check if YourDataGrid.SelectedRows.Count > 0

        C# controls, .Net components. Help Desk Software

        1 Reply Last reply
        0
        • M M Riaz Bashir

          Hi everyone, I am working in button click event and i want to get row index of selected row. Kindly let me kknow. Thank you in advance (Riaz)

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          This is how to get selected row from DataGridView in .NET 2.0 Make sure there’s a single cell that is currently selected Get current row index using {datagridview instance}.CurrentCell.RowIdex Get the selected row using {datagridview instance}.Rows({current row index}).Cells({zero based index}).Value Here’s the sample code : Dim crow = DataGridView1.CurrentCell.RowIndex dim txt as string Try txt = DataGridView1.Rows(crow).Cells(0).Value & ” || ” txt = txt & DataGridView1.Rows(crow).Cells(1).Value & ” || ” txt = txt & DataGridView1.Rows(crow).Cells(2).Value MessageBox.show (txt) Catch ex As Exception ‘ do nothing End Try

          WaelA Senior Software Engineer http://www.linkedin.com/in/waelalwirr abu_wer@hotmail.com

          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