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. Help. I'm Lost. How to retrieve the selected row information from a DataGridView

Help. I'm Lost. How to retrieve the selected row information from a DataGridView

Scheduled Pinned Locked Moved C#
helpdatabasesalestutorialquestion
6 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.
  • T Offline
    T Offline
    TheFoZ
    wrote on last edited by
    #1

    Hi. I'm having trouble with a DataGridView. The view displays a list of customers from a query that displays their relevant ID's and names which is bound to a DataTable. When the user double clicks on the customer they want, I would like to get the customer ID of their selection. I've tried customerDataGrid.SelectedRows(0).Cells(0).Value but I get an error saying that SelectedRows is a property but it is being used as a method. How do I achieve this. I know it is probably simple but I cannot find the info that I need on MSDN and I am at a loss. Your help is much appreciated in advance.

    The FoZ

    L 1 Reply Last reply
    0
    • T TheFoZ

      Hi. I'm having trouble with a DataGridView. The view displays a list of customers from a query that displays their relevant ID's and names which is bound to a DataTable. When the user double clicks on the customer they want, I would like to get the customer ID of their selection. I've tried customerDataGrid.SelectedRows(0).Cells(0).Value but I get an error saying that SelectedRows is a property but it is being used as a method. How do I achieve this. I know it is probably simple but I cannot find the info that I need on MSDN and I am at a loss. Your help is much appreciated in advance.

      The FoZ

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

      TheFoZ wrote:

      but I get an error saying that SelectedRows is a property but it is being used as a method.

      Yeah, because that's what it is. customerDataGrid.SelectedRows[0].Cells[0].Value regards

      T 1 Reply Last reply
      0
      • L Lost User

        TheFoZ wrote:

        but I get an error saying that SelectedRows is a property but it is being used as a method.

        Yeah, because that's what it is. customerDataGrid.SelectedRows[0].Cells[0].Value regards

        T Offline
        T Offline
        TheFoZ
        wrote on last edited by
        #3

        Looks like I'm still in my VB ways with curved brackets instead of square ones. Many Thanks

        The FoZ

        H 1 Reply Last reply
        0
        • T TheFoZ

          Looks like I'm still in my VB ways with curved brackets instead of square ones. Many Thanks

          The FoZ

          H Offline
          H Offline
          Harvey Saayman
          wrote on last edited by
          #4

          hey there also you should keep in mind that it is posible to have more than one selected row in a dataGridView unless otherwise set up by you in design time. if thats desired youll have to do the following... foreach(DataGridRow myRow in myDataGrid.Rows) { // do what ever you need to do with the row }

          Harvey Saayman - South Africa Junior Developer .Net, C#, SQL

          you.suck = (you.passion != Programming)

          T P 2 Replies Last reply
          0
          • H Harvey Saayman

            hey there also you should keep in mind that it is posible to have more than one selected row in a dataGridView unless otherwise set up by you in design time. if thats desired youll have to do the following... foreach(DataGridRow myRow in myDataGrid.Rows) { // do what ever you need to do with the row }

            Harvey Saayman - South Africa Junior Developer .Net, C#, SQL

            you.suck = (you.passion != Programming)

            T Offline
            T Offline
            TheFoZ
            wrote on last edited by
            #5

            Thanks for that. It will come in use later on in the project.

            The FoZ

            1 Reply Last reply
            0
            • H Harvey Saayman

              hey there also you should keep in mind that it is posible to have more than one selected row in a dataGridView unless otherwise set up by you in design time. if thats desired youll have to do the following... foreach(DataGridRow myRow in myDataGrid.Rows) { // do what ever you need to do with the row }

              Harvey Saayman - South Africa Junior Developer .Net, C#, SQL

              you.suck = (you.passion != Programming)

              P Offline
              P Offline
              Paul Conrad
              wrote on last edited by
              #6

              HarveySaayman wrote:

              posible to have more than one selected row in a dataGridView unless otherwise set up by you in design time

              Yes. You can use datagridview1.MultiSelect=false for only allowing one. Brought this up to my students the other day in class.

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

              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