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. Datagridview.selectedValue help?

Datagridview.selectedValue help?

Scheduled Pinned Locked Moved C#
helpquestion
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.
  • P Offline
    P Offline
    PyroManiak
    wrote on last edited by
    #1

    I'm trying to find a way to grab a given rows cell information, for now just the primary key, and store it in a variable to use somewhere else. If I use listbox's I can simply use .selectedValue() and it gives me exactly what I need, but in this case, I'm needing to do it with a datagridview and this attribute doesn't exist. Thanks!

    M 1 Reply Last reply
    0
    • P PyroManiak

      I'm trying to find a way to grab a given rows cell information, for now just the primary key, and store it in a variable to use somewhere else. If I use listbox's I can simply use .selectedValue() and it gives me exactly what I need, but in this case, I'm needing to do it with a datagridview and this attribute doesn't exist. Thanks!

      M Offline
      M Offline
      Mairaaj Khan
      wrote on last edited by
      #2

      PyroManiak wrote:

      I'm trying to find a way to grab a given rows cell information, for now just the primary key, and store it in a variable to use somewhere else.

      If your DataGridView is populated through a DataSource, then the following code snippet might help you.

      stringVariable = dataGridView.Rows[index].Cells[index].Value.toString();

      Here index could be an integer value or variable holding a value: and is zero (0) based. Alternatively you can use Column name as Cells index, like:

      stringVariable = dataGridView.Rows[index].Cells["ColumnName"].Value.toString();

      Also you can get the value from the selected or Current row, like this:

      stringVariable = dataGridView.CurrentRow.Cells[index].Value.toString();

      Using the same technique you cann't get value from an unbound datagridview Hope this would solve your problem. Best of Luck. _____________________________ Success is not something to wait for, its something to work for.

      P 1 Reply Last reply
      0
      • M Mairaaj Khan

        PyroManiak wrote:

        I'm trying to find a way to grab a given rows cell information, for now just the primary key, and store it in a variable to use somewhere else.

        If your DataGridView is populated through a DataSource, then the following code snippet might help you.

        stringVariable = dataGridView.Rows[index].Cells[index].Value.toString();

        Here index could be an integer value or variable holding a value: and is zero (0) based. Alternatively you can use Column name as Cells index, like:

        stringVariable = dataGridView.Rows[index].Cells["ColumnName"].Value.toString();

        Also you can get the value from the selected or Current row, like this:

        stringVariable = dataGridView.CurrentRow.Cells[index].Value.toString();

        Using the same technique you cann't get value from an unbound datagridview Hope this would solve your problem. Best of Luck. _____________________________ Success is not something to wait for, its something to work for.

        P Offline
        P Offline
        PyroManiak
        wrote on last edited by
        #3

        stringVariable = dataGridView.CurrentRow.Cells[index].Value.toString(); That worked for my purposes just great! Thanks a bunch!

        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