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. Datagrid Binding to an Object

Datagrid Binding to an Object

Scheduled Pinned Locked Moved C#
wpfwcfhelpquestion
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.
  • W Offline
    W Offline
    wgroves
    wrote on last edited by
    #1

    I'm really struggling trying to bind a Datagrid to a collection of objects. I understand that for each public property of the objects in the collection, a column will be displayed. But I don't want to display a column for all of the public properties, just some of them. And I also want to add columns to the datagrid for things like an image that is associated with one of the properties. How do you hide columns when binding to objects? How do you add columns to a datagrid when it is bound to a collection of objects? Any help would be greatly appreciated! Thanks Warwick "I hear they've even got the internet on Computers now." - Homer Simpson

    J N 2 Replies Last reply
    0
    • W wgroves

      I'm really struggling trying to bind a Datagrid to a collection of objects. I understand that for each public property of the objects in the collection, a column will be displayed. But I don't want to display a column for all of the public properties, just some of them. And I also want to add columns to the datagrid for things like an image that is associated with one of the properties. How do you hide columns when binding to objects? How do you add columns to a datagrid when it is bound to a collection of objects? Any help would be greatly appreciated! Thanks Warwick "I hear they've even got the internet on Computers now." - Homer Simpson

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      If you databind a datagrid to a list of objects, it will create a column for each property as you said. However, if you first create a DataGridTableStyle and add to it the DataGridColumnStyle objects that you want then only those columns will be shown. This can be done directly in the designer.

      W 1 Reply Last reply
      0
      • J J4amieC

        If you databind a datagrid to a list of objects, it will create a column for each property as you said. However, if you first create a DataGridTableStyle and add to it the DataGridColumnStyle objects that you want then only those columns will be shown. This can be done directly in the designer.

        W Offline
        W Offline
        wgroves
        wrote on last edited by
        #3

        Thanks! I've just had a look at TableStyles/ColumnStyles and will try it today. Cheers Warwick :) "I hear they've even got the internet on Computers now." - Homer Simpson

        1 Reply Last reply
        0
        • W wgroves

          I'm really struggling trying to bind a Datagrid to a collection of objects. I understand that for each public property of the objects in the collection, a column will be displayed. But I don't want to display a column for all of the public properties, just some of them. And I also want to add columns to the datagrid for things like an image that is associated with one of the properties. How do you hide columns when binding to objects? How do you add columns to a datagrid when it is bound to a collection of objects? Any help would be greatly appreciated! Thanks Warwick "I hear they've even got the internet on Computers now." - Homer Simpson

          N Offline
          N Offline
          n10sive
          wrote on last edited by
          #4

          Take a look at ITypedList. Adding it to your collection allows you to create property descriptors. The Datagrid will respect this list. This is more "class friendly" to implementers and they won't have to use table styles to get rid of the unfriendly stuff.

          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