0

I've been tasked at work with creating a UserControl containing a ListView and ComboBox's for sorting the ListView data. Sorting with the Combobox's s the easy part; the part with which I'm having difficulty is implementing a method of scrolling. In the end, the control should have an Excel-like feel to it. However, sometimes the ListView is too tall or wide for where it is placed. Therefore, there two be two scrollbars somewhere on the control. One vertically moves of the ListView only, and the other moves both the ListView and ComboBox filters horizontally.

Very basic mock-up of what the end result should be

Please note in the image above that the ComboBox's do adjust themselves according to column width, but the code for that is not enabled at the moment.

What I've tried: In the control, the filter boxes are in their own panel, and the ListView has had its own panel at times. I've tried using various combinations of the HScroll/VScroll and HorizontalScroll/VerticalScroll properties and the native function ShowScrollBar() for all the controls, but nothing has worked. The only way I've gotten scrollbars to appear is by settings AutoScroll (Scrollable for the ListView) to true. Of course, the scroll bars come in pairs and work only on the same control. I also attempted to programmatically move the scroll bars, but I haven't been able to accomplish that, either.

I've got to be doing something wrong, but I'm not sure what it is. Any help is appreciated!

wisner
  • 523
  • 1
  • 5
  • 18
  • I strongly recommend WPF for this. winforms doesn't support big UIs as has been demonstrated over and over here in StackOverflow. – Federico Berasategui Aug 08 '14 at 15:19
  • HighCore: I wish I could use WPF. The program I'm working on was written in 2005 and only used .NET 2.0 until I came along. It simply has too many forms for my boss to let me replace them. Actually, he had never heard of WPF until I started this job. Can I easily mix Winforms/WPF? – wisner Aug 08 '14 at 15:30
  • Right, I misread the question, sorry. – TaW Aug 08 '14 at 15:34
  • It's not ideal, but it's still a good idea. If you want to post that as an answer, I'll accept it. Thanks! – wisner Aug 08 '14 at 15:47
  • @wisner yes you can add WPF `Window`s to a winforms project, or even put WPF content (UserControl) in a winforms `Form` via the `ElementHost`. All in all, winforms/WPF interop is quite easy and doable. Provided of course you're targeting .Net 3.0 and above. – Federico Berasategui Aug 08 '14 at 16:00
  • @HighCore, I know you'll downvote anything Winforms I post, but with all due respect: __This.Is.Not.A.Big.UI.__ – TaW Aug 08 '14 at 16:19
  • @HighCore, yours is the preferable solution, but the control is due by the end of the work day, and I don't feel I could make that deadline using WPF. TaW's answer is more ideal given the time constraint. Still, maybe you could post your answer, too. In the long run, I can see it being more helpful to others. – wisner Aug 08 '14 at 16:24

1 Answers1

0

I think I'd go for a different solution.

If you put the ComboBoxes in a AutoSrcoll panel with the same Anchors as the ListView you would give your users the freedom to scroll the two independently.

Yes, a ScrollBar would appear and take space but I would still happily sell that as a feature, not a bug ;-)

As for handling the Scroll event of a ListView: It is hidden and you'll have to subclass it to get access to it. See here

Community
  • 1
  • 1
TaW
  • 53,122
  • 8
  • 69
  • 111