Listview with auto generation of column + enable disable columns

hello guys,

Back in the days of winforms in .Net 2.0 and 1.1, one of the controls that I really loved was the datagridview aka datagrid.

One of the most powerful features of the data grid was that if you wanted to; you could just specify an ItemsSource and the datagridview would create all the column for you. The data grid would do this by looking at the object properties by reflection. Unfortunatly WPF does not have such a control, yet WPF is flexible enough to let you do something similar by using the listview.

I have developed a similar control to the DataGridView that supports auto generation of columns by looking at the properties of the object that you push from the ItemsSource…

Auto generation of columns sometimes is to implicit. Sometimes you would like to order your column, exclude a property from showing in the listview or even display the header text differently than the property name… My solution was to create a custom attribute that can specify additional information for the datagridview control. This is very easy to use but yes, you are coupling the business object with UI specific information, so please if anyone has some feedback/ideas how I can improve this let me know…

Another interesting feature that this control supports is the concept of having Collections as propeties. The question here is “How do I represent the data of my collection in the listview?”.
Well from experiance I can say that usually you would need only the count of the collection or maybe the last value of the collection (maybe even something else that is truly custom), so what i have introduced to the control is the CollectionBehaviour. This is an enum that currently supports Count and LastValue yet eventually I m going to refactor the control to support even custom behaviours. I implement this by using the Stratagy design pattern where I have a ICollectionNotificationStrategy interface and 2 different class that implement a different strategy one for the count and one for the last value. In this way the collection behaviour is scalable enough to eventually support custom behaviours…(I will introduce this feature next week)

This control also supports enable and disable of column…. Yes, as you know the WPF listview does not dirrectly support this feature, so I decided to add it in the datagridview….

The Future…

I am planning to support sorting and paging. And maybe even sorting on property notifictaions… This will not be easy since sorting on property notifications implies a performance hit… but yes, I will try to do it…

enough talking… guys feel free to download the sorce code + demo of this control here

please send feed back….

17 thoughts on “Listview with auto generation of column + enable disable columns

  1. Ok… downloaded the code, looked at it very lightly (saturday night) and all I can tell you at the moment is, good job with the unit tests. At least in my old age I can say, Damn, someone was listening to my Yakking.

    Now, that aside. What do you mean with “too implicit?” Consider the average user – not a power-coder like you. Just an average, out-of-school coder, on an average project.

    I like configurable stuff – saves a LOT of time on those crazy projects we all love (though we may not all admit it) but you know your market – are you sure that’s what they want?

    I haven’t tried Ruby yet, but their Sales Pitch (note caps) on convention over configuration sure looks attractive. 😉

  2. Hello there….

    What I mean by too implicit is that sometimes the property that you have for the specific object does not have enough info to show in the grid… for example as we all know you cannot have spaces in the property name so you would create a property that looks like this


    but you want this property to show in the column header like this

    My Property

    This is the whole purpose of the DataGridViewPropertyDescriptorAttribute. You use this attribute to give more information about your property to the datagrid, so that the column gets generated exactly how you want it…

    Thanks a lot for the feed back…

  3. At a glance it seems very useful for WPF applications which need similar controls like the old DataGrid.

    So I should say – Great Job! 😀

    I’ll try to actually implement it in a sample application so I’ll better understand its power and give you better feedback later.

    Thanks and keep updating the blog! Hope we will have more interesting controls from you in the future 😉

  4. Pingback: JaaBlog » Blog archief » WPF ListView

  5. Pingback: GridViewColumn DisplayMemberBinding vs CellTemplate « C# Disciples

  6. Excellent Work! This small tool will really help extend our list functionality. Can you describe how one would disable say, the first column in the gridlistview and allow scrolling on the remainder?

    “This control also supports enable and disable of column…. Yes, as you know the WPF listview does not dirrectly support this feature, so I decided to add it in the datagridview….”


  7. Thanks Marlon , Great Job! , I made some minor change , and now I be able to bind also DataTables. I am planning other improvements like horizontal align columns acording to the type of data containing.

    Greetings from Uruguay.

  8. Thanks Marlon, good stuff here. I managed to convert both this and the datepicker to vb. Any ideas on adding some style to the column headers on the grid?

  9. Marlon, I’ve downloaded the avalon libraries. Where can I find documentatiion? Specifically I need documentation for the datagridview control.

  10. Pingback: A Better WPF DataGrid – Part 3 | BadImageFormat

  11. Its amazing how long the electric vehicle has been around, and why development didn’t continue back then. Instead we waited how many years to get back to developing this type of car.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s