Using C# .NET 2.0, I have an owner-drawn ListView where I’m overriding the OnDrawColumnHeader, OnDrawItem and OnDrawSubitem events. If I set the View property to Details at design-time, everything works beautifully and I can switch the View property and all view modes display as they should (I’m not using Tile view). However, if I start in any other View, both the List and Details views are blank.
I know you’ll probably want to see code, but there’s a lot of it, so I’m hesitant to post that much, but can if necessary. I’m more curious if someone has seen this before, and/or might have an inkling of how to fix it. The View property will be a user-saved setting, so I won’t always be able to start in Details view by default.
The WinForms ListView is mostly a layer of abstraction of the top of the actual Windows control, so there are aspect of its behaviour that are, well, counterintuitive is a polite way of putting things.
I have a vague recollection, from back in my days as a Delphi developer, that when you are Owner drawing a ListView, the subitems of the control aren’t actually populated unless your Listview is in ‘Details’ mode when you load the items.
Things to try …
… force the WinForms control to recreate the underlying windows handle after you change the display style. If memory serves, DestroyHandle() is the method you want.
… assuming you have a ‘Refresh’ in your application to reload the data, do things work properly when you refresh after changing the display style?
… if all else fails, beg borrow or steal a copy of Charles’ Petzolds classic on windows programming.