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. Getting the value of a column of selected row in DataGridView

Getting the value of a column of selected row in DataGridView

Scheduled Pinned Locked Moved C#
csharphelp
3 Posts 3 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.
  • V Offline
    V Offline
    VijayaRam
    wrote on last edited by
    #1

    Hi, I have problem in retrieving the value of a column of selected row in DataGridView control using c#.net 2005

    VijayaRam

    H I 2 Replies Last reply
    0
    • V VijayaRam

      Hi, I have problem in retrieving the value of a column of selected row in DataGridView control using c#.net 2005

      VijayaRam

      H Offline
      H Offline
      Herman T Instance
      wrote on last edited by
      #2

      easy one public String returnGridViewCellValue(GridViewRow row, String fieldName) { String result = String.Empty; try { result = DataBinder.Eval(row.DataItem, fieldName).ToString(); } catch { result = String.Empty; // or result = fieldName + " not found"; } return result; }

      1 Reply Last reply
      0
      • V VijayaRam

        Hi, I have problem in retrieving the value of a column of selected row in DataGridView control using c#.net 2005

        VijayaRam

        I Offline
        I Offline
        il_masacratore
        wrote on last edited by
        #3

        Here is an example(getting the value of a cell of the first row selected ): DatagridView oGrid; //If you know the ordinal of the column if( oGrid.SelectedRows.Count>0 ) { object oValue = oGrid.SelectedRows[0].Cells[0].Value; } //If you know the name of the column if( oGrid.SelectedRows.Count>0 ) { object oValue = oGrid.SelectedRows[0].Cells["colName"].Value; } //Then you can try to Convert the object to a different type.

        Visit my blog at http://dotnetforeveryone.blogspot.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