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. Problem with columns in DataGridView

Problem with columns in DataGridView

Scheduled Pinned Locked Moved C#
databasehelpquestion
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.
  • K Offline
    K Offline
    Knoen
    wrote on last edited by
    #1

    Im trying to access a certan column in a data bound DataGridView like this. int index = (int)dataGridView1.Columns["SomeColumn"].DisplayIndex; But some how i allways got the "dataGridView1.Columns["SomeColumn"]" to be null. That is it is not set to an object. But if i use the syntax int index = (int)dataGridView1.Columns[0].DisplayIndex it works fine! Any ideas? Ive got nothing :) Thankz

    L 1 Reply Last reply
    0
    • K Knoen

      Im trying to access a certan column in a data bound DataGridView like this. int index = (int)dataGridView1.Columns["SomeColumn"].DisplayIndex; But some how i allways got the "dataGridView1.Columns["SomeColumn"]" to be null. That is it is not set to an object. But if i use the syntax int index = (int)dataGridView1.Columns[0].DisplayIndex it works fine! Any ideas? Ive got nothing :) Thankz

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      dataGridView1.Columns[0].Name

      K 1 Reply Last reply
      0
      • L led mike

        dataGridView1.Columns[0].Name

        K Offline
        K Offline
        Knoen
        wrote on last edited by
        #3

        Yes but isnt it possible to access both like Columns[integer] and Columns[String]? Then i dont have to know the actual index for the column i seek. Thats the beauti :)

        L 1 Reply Last reply
        0
        • K Knoen

          Yes but isnt it possible to access both like Columns[integer] and Columns[String]? Then i dont have to know the actual index for the column i seek. Thats the beauti :)

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          See, I know that Columns[string] works so without further evidence I am forced to assume that you are not using a valid string value. My post was suggesting that you look at the Name properties of all the columns to find your error. Apparently my short post was not enough to steer you in that direction.

          K 1 Reply Last reply
          0
          • L led mike

            See, I know that Columns[string] works so without further evidence I am forced to assume that you are not using a valid string value. My post was suggesting that you look at the Name properties of all the columns to find your error. Apparently my short post was not enough to steer you in that direction.

            K Offline
            K Offline
            Knoen
            wrote on last edited by
            #5

            Oh man! You where right, what a god damn rockie misstake :) In the database the columns name i CustomerID so naturaly i tryed that. But the true name was customerIDDataGridViewTextBoxColumn :(( Thanks for the help!

            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