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. Collecting values from datagridview.selectedrows[0].cells

Collecting values from datagridview.selectedrows[0].cells

Scheduled Pinned Locked Moved C#
help
5 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.
  • L Offline
    L Offline
    Lodeclaw
    wrote on last edited by
    #1

    I'm trying to collect the values from a datagridview in a child form and place them in textboxes located in it's parent form. I'm using the following statement for one of the values:

    txtFirstName.Text = this.finder.dataGridView1.SelectedRows[0].Cells["firstNameDataGridViewTextBoxColumn"].Value.ToString();

    As far as I can tell, it should be working. When I run the program, once it gets to this point it throws an error telling me that the values are null. There are no spelling errors. "finder" is the child form. Please help.:confused:

    C 1 Reply Last reply
    0
    • L Lodeclaw

      I'm trying to collect the values from a datagridview in a child form and place them in textboxes located in it's parent form. I'm using the following statement for one of the values:

      txtFirstName.Text = this.finder.dataGridView1.SelectedRows[0].Cells["firstNameDataGridViewTextBoxColumn"].Value.ToString();

      As far as I can tell, it should be working. When I run the program, once it gets to this point it throws an error telling me that the values are null. There are no spelling errors. "finder" is the child form. Please help.:confused:

      C Offline
      C Offline
      Cassandra Ross
      wrote on last edited by
      #2

      Have you tried determining which part of the statement is null? Are you trying to just get the first selected row and are you sure there is a row selected?

      L 1 Reply Last reply
      0
      • C Cassandra Ross

        Have you tried determining which part of the statement is null? Are you trying to just get the first selected row and are you sure there is a row selected?

        L Offline
        L Offline
        Lodeclaw
        wrote on last edited by
        #3

        Sorry, maybe I'm misunderstanding the error message. It's not exactly telling me the value is null... The message I'm getting is, "Object reference not set to an instance of an object." It's pointed at "firstNameDataGridViewTextBoxColumn". After some testing I'm finding the same error on my search statement to fill my datagridview, now, as well:

        this.finder.customerTableAdapter.FillByFirstLastPhoneNo(this.finder.edsDBDataSet.Customer, txtLastName.Text, txtFirstName.Text, txtPhone.Text);

        If I catch it, however, it continues and fills the datagridview normally, dispite throwing this exception. I'm still pretty green with this, unfortunately. I'm really not quite sure what exactly is going wrong, since it didn't have this problem earlier.

        C 1 Reply Last reply
        0
        • L Lodeclaw

          Sorry, maybe I'm misunderstanding the error message. It's not exactly telling me the value is null... The message I'm getting is, "Object reference not set to an instance of an object." It's pointed at "firstNameDataGridViewTextBoxColumn". After some testing I'm finding the same error on my search statement to fill my datagridview, now, as well:

          this.finder.customerTableAdapter.FillByFirstLastPhoneNo(this.finder.edsDBDataSet.Customer, txtLastName.Text, txtFirstName.Text, txtPhone.Text);

          If I catch it, however, it continues and fills the datagridview normally, dispite throwing this exception. I'm still pretty green with this, unfortunately. I'm really not quite sure what exactly is going wrong, since it didn't have this problem earlier.

          C Offline
          C Offline
          Cassandra Ross
          wrote on last edited by
          #4

          The error message usually means that one of the objects has not been created. This could be due to the column not existing or rows not being selected. Are you checking that SelectedRows.Count is greater than 0? If there are no explicitly selected rows then this could be the problem.

          L 1 Reply Last reply
          0
          • C Cassandra Ross

            The error message usually means that one of the objects has not been created. This could be due to the column not existing or rows not being selected. Are you checking that SelectedRows.Count is greater than 0? If there are no explicitly selected rows then this could be the problem.

            L Offline
            L Offline
            Lodeclaw
            wrote on last edited by
            #5

            It looks as though the problem lies in my sql query. I'm not sure how it went wrong, since I've been using it successfully for a week. Reconfiguring the query has not helped, either. My query is as follows:

            SELECT Address, Customer_ID, First_Name, Last_Name, Phone_No FROM Customer
            WHERE (Last_Name LIKE @Last_Name) AND (First_Name LIKE @First_Name) AND (Phone_No LIKE @Phone_No)

            called by the code I posted previously:

            this.finder.customerTableAdapter.FillByFirstLastPhoneNo(this.finder.edsDBDataSet.Customer, txtLastName.Text, txtFirstName.Text, txtPhone.Text);

            Thank you for trying to help thus far. I'll keep working on this; maybe someone will have some insight on what's going wrong. :wtf:

            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