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. Best way to populate this DataGridView

Best way to populate this DataGridView

Scheduled Pinned Locked Moved C#
helptutorialquestion
4 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.
  • B Offline
    B Offline
    BDJones
    wrote on last edited by
    #1

    Happy new year... I have a list of objects I would like to use to populate a datagridview. I would somehow like to have each row bound to a specific object. I can see how that object class can be added as a datasource, but I'm not sure how to get the objects from my list added as a row. Anyone care to help? Also, is this the right direction? Thanks for your time.

    L D 2 Replies Last reply
    0
    • B BDJones

      Happy new year... I have a list of objects I would like to use to populate a datagridview. I would somehow like to have each row bound to a specific object. I can see how that object class can be added as a datasource, but I'm not sure how to get the objects from my list added as a row. Anyone care to help? Also, is this the right direction? Thanks for your time.

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

      After set the datasource, you must enumerate each row and set the row.Tag to your object.

      B 1 Reply Last reply
      0
      • B BDJones

        Happy new year... I have a list of objects I would like to use to populate a datagridview. I would somehow like to have each row bound to a specific object. I can see how that object class can be added as a datasource, but I'm not sure how to get the objects from my list added as a row. Anyone care to help? Also, is this the right direction? Thanks for your time.

        D Offline
        D Offline
        darkelv
        wrote on last edited by
        #3

        You can retrieve the object via DataBoundItem property.

        1 Reply Last reply
        0
        • L Lost User

          After set the datasource, you must enumerate each row and set the row.Tag to your object.

          B Offline
          B Offline
          BDJones
          wrote on last edited by
          #4

          Before the grid is populated, there are no rows to enumerate in the grid. If the class is used as a datasource, adding rows 'dgView.Rows.Add()' creates an exception stating 'Rows cannot be programmatically added to the DataGridView's row collection' I'm using the class as the view bindng source. If this is correct, how do I get the list of obects into the grid? If there is a different approach that would be better than what I'm attempting, please comment. Thank you for your time.

          modified on Sunday, January 3, 2010 12:04 PM

          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