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 Collection

DataGrid, binding to Collection

Scheduled Pinned Locked Moved C#
csharpasp-netwpfwcftutorial
4 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.
  • P Offline
    P Offline
    partyganger
    wrote on last edited by
    #1

    First of all, I'm kind of a n00b on C# (only been at it for 3 months on and of now..) I'm trying to bind a DataGrid to a collection (that is strongly typed, has IBindingList etc. implemented), but I don't want all fields shown (like Id, InsertTime, updateTime etc.) I've 'been looking all over the internet but can't find anything about the subject, everything I find is about DataTable/DataSets, or about ASP.NET, where the DataGrid has an AutoGenerateColumns boolean that you can set to false. Does anyone here have an example I could look at?

    W 1 Reply Last reply
    0
    • P partyganger

      First of all, I'm kind of a n00b on C# (only been at it for 3 months on and of now..) I'm trying to bind a DataGrid to a collection (that is strongly typed, has IBindingList etc. implemented), but I don't want all fields shown (like Id, InsertTime, updateTime etc.) I've 'been looking all over the internet but can't find anything about the subject, everything I find is about DataTable/DataSets, or about ASP.NET, where the DataGrid has an AutoGenerateColumns boolean that you can set to false. Does anyone here have an example I could look at?

      W Offline
      W Offline
      Wjousts
      wrote on last edited by
      #2

      Create you own DataGridTableStyle and map it to your datasource. Then create GridColumnStyles for each field you want to display, and add them to your DataGridTableStyle. Finally add the DataGridTableStyle to your DataGrid. If you get the mapping right (which can be a little tricky!) it should display your TableStyle and only the columns you added to the TableStyle.

      P 1 Reply Last reply
      0
      • W Wjousts

        Create you own DataGridTableStyle and map it to your datasource. Then create GridColumnStyles for each field you want to display, and add them to your DataGridTableStyle. Finally add the DataGridTableStyle to your DataGrid. If you get the mapping right (which can be a little tricky!) it should display your TableStyle and only the columns you added to the TableStyle.

        P Offline
        P Offline
        partyganger
        wrote on last edited by
        #3

        Just found it out myself :-D. If you create the GridStyle, you have to set it's mappingname to the type of your Collection, so if your collection is of Type CompanyCollection, that should be the mappingname. Tricky indeed...

        W 1 Reply Last reply
        0
        • P partyganger

          Just found it out myself :-D. If you create the GridStyle, you have to set it's mappingname to the type of your Collection, so if your collection is of Type CompanyCollection, that should be the mappingname. Tricky indeed...

          W Offline
          W Offline
          Wjousts
          wrote on last edited by
          #4

          partyganger wrote: Tricky indeed... What I meant is that (IMHO) it doesn't parallel what you do with a dataset. In a dataset you give it the name of the table, so (again IMHO) with a collection you might expect to give it the name of that instance of the collection or maybe the name of a property in your class (if you class wrapped a collection), but you don't, you give it the name of the type of the collection (as you rightly pointed out). That seem counter-intuitive to me and it also means that you can't switch a datagrid from binding one collection object to another collection object of the same type and expect it to automatically switch styles (because they'd both use the same mapping). Sheez...sorry I bothered :~

          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