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. WPF
  4. adding/removing ListView columns at runtime (revisited)

adding/removing ListView columns at runtime (revisited)

Scheduled Pinned Locked Moved WPF
wpfquestioncsharpwcfcom
3 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.
  • V Offline
    V Offline
    Vincent Beek
    wrote on last edited by
    #1

    Some time ago I asked here the question how to code adding/removing columns to a Listview at runtime and 'binding columns to viewmodels' SeldgeHammer came with this solution: 1) The WPF ListView doesn't support data binding on the GridViewColumnCollection out of the box. You can add support for this, not too difficult, but a little bit of work. 2) Once you have a WPF ListView that can support data binding on the GridViewColumnCollection, its just a matter of having your VM return a collection of columns. 3) Some gotcha's you'll run into: a) a GridViewColumn can only be owned by one GridViewColumnCollection at a time, so you can't return a GridViewColumnCollection from your VM, you need to return an ObservableCollection. b) defining a GridViewColumn in code with bindings is a major PITA, so you should devise a way to load them out of a XAML file where you'll again run into "issue a" where you can't share GridViewColumn's. All these issues are overcomeable... basically what I ended up with was a GridViewEx class that supported two-way binding on the column collection. Remember, you are going to need to save column widths and column order . I wanted to share a blog on this topic that I ran into the other day. I quite like the solution provided there. Sharing info never hurts right? :) http://blogs.msdn.com/b/nathannesbit/archive/2009/03/13/developing-reusable-controls-with-the-model-view-viewmodel-pattern.aspx[^]

    A 1 Reply Last reply
    0
    • V Vincent Beek

      Some time ago I asked here the question how to code adding/removing columns to a Listview at runtime and 'binding columns to viewmodels' SeldgeHammer came with this solution: 1) The WPF ListView doesn't support data binding on the GridViewColumnCollection out of the box. You can add support for this, not too difficult, but a little bit of work. 2) Once you have a WPF ListView that can support data binding on the GridViewColumnCollection, its just a matter of having your VM return a collection of columns. 3) Some gotcha's you'll run into: a) a GridViewColumn can only be owned by one GridViewColumnCollection at a time, so you can't return a GridViewColumnCollection from your VM, you need to return an ObservableCollection. b) defining a GridViewColumn in code with bindings is a major PITA, so you should devise a way to load them out of a XAML file where you'll again run into "issue a" where you can't share GridViewColumn's. All these issues are overcomeable... basically what I ended up with was a GridViewEx class that supported two-way binding on the column collection. Remember, you are going to need to save column widths and column order . I wanted to share a blog on this topic that I ran into the other day. I quite like the solution provided there. Sharing info never hurts right? :) http://blogs.msdn.com/b/nathannesbit/archive/2009/03/13/developing-reusable-controls-with-the-model-view-viewmodel-pattern.aspx[^]

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      Thanks but you could always consider posting this blog under the original question rather than here. This isn't a question. :)

      M 1 Reply Last reply
      0
      • A Abhinav S

        Thanks but you could always consider posting this blog under the original question rather than here. This isn't a question. :)

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        I doubt he is the author of the blog, so sharing in this manner is excellent, he got my 5

        Never underestimate the power of human stupidity RAH

        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