I'm new to Windows Forms (and .NET in general, for that matter) and I'm in a bit of a spot. I have a control (a TableLayoutPanel to be specific) that is dynamically and programatically sized (specifically by adding and deleting rows) based on certain criteria.
This works fine, but I need to put this inside another TableLayoutPanel of one column where the top row, containing the dynamically-sized control, sizes itself to the size of the control, and the bottom row then takes up the rest of the space. Now, I did this by making the top row be autosize'd and the bottom row take up 100%, but here's the problem: The control in the bottom row (a ListView) has a minimum size property set on it. What needs to happen is that, if that bottom row can't be sized any smaller to accomodate the top row, the whole TableLayoutPanel needs to scroll.
I tried turning on AutoSize in the TableLayoutPanel, but it doesn't seem to respect it; the whole panel just extends down past the bottom of the form. I tried containing the TableLayoutPanel in a simple Panel control and turning autosize on in the panel, but still no luck.
What's the preferred way to do this?
Thanks for any help you guys can give me! | | Magicmat Wednesday, August 08, 2007 7:30 AM | Hmm, that gets me closer, but I'm still having problems. In the Form() method, right after InitializeComponent(), as well as in an Resize event, I set the AutoScrollMinSize value of the TableLayoutPanel to be the same as the TableLayoutPanel's Size property. However, when I expand the TableLayoutPanel, it still goes down past the bottom of the form. It's not until I expand the form 'till I can see all the controls, and the resize it so that some of the controls are hidden again that the scroll bars turn on.
Secondly, I have a problem where the Dock:Fill'ed ListView control, contained in the bottom row of the TableLayoutPanel (which is set to AutoSize) will expand out just fine with the window, but will never shrink back down again once the scroll bars have kicked in. It will grow and shrink just fine before I implemented the scrolling system, but now it's borked.
Thanks for the help, though; I feel like I'm finally on the right track.
| | Magicmat Sunday, August 12, 2007 4:22 AM | I faced a similar problem. I set the AutoScrollMinSize to the controller's sizethat will be scrolled. This worked fine to me. | | Ronaldo Ferreira Friday, August 10, 2007 10:31 PM | Hmm, that gets me closer, but I'm still having problems. In the Form() method, right after InitializeComponent(), as well as in an Resize event, I set the AutoScrollMinSize value of the TableLayoutPanel to be the same as the TableLayoutPanel's Size property. However, when I expand the TableLayoutPanel, it still goes down past the bottom of the form. It's not until I expand the form 'till I can see all the controls, and the resize it so that some of the controls are hidden again that the scroll bars turn on.
Secondly, I have a problem where the Dock:Fill'ed ListView control, contained in the bottom row of the TableLayoutPanel (which is set to AutoSize) will expand out just fine with the window, but will never shrink back down again once the scroll bars have kicked in. It will grow and shrink just fine before I implemented the scrolling system, but now it's borked.
Thanks for the help, though; I feel like I'm finally on the right track.
| | Magicmat Sunday, August 12, 2007 4:22 AM | I'd love to know if you ever found a way to make the autoscrolling TableLayoutPanel shrink back down when rows are removed. I'm havinga heck of a time with the same issue. It makes me wish for an AutoScrollMaxSize to complement the AutoScrollMinSize. | | JayStation3 Friday, January 11, 2008 12:21 AM | (Sorry for the delay in replying, my account here is linked with my Hotmail account, which I never check. I really need to look into changing that. Edit: It looks like I can't. Hooray MS business practicates! Oh well, GMail will never let me down.)
Unfortunately, I was unable to ever really solve the problem to my satisfaction. Eventually I just changed my design to not require all the compliacted stuff above. A more programmatically mature design, but I'm not sure if the user experience is any better off for my abandonment of my original design. | | Magicmat Wednesday, February 13, 2008 1:07 AM | I found a solution: Whenever I change the size of a row (for example, which extends the TableLayoutPanel and never shrinks it again), I do this: tableLayoutPanel1.AutoScroll = false; // change row size by changing the row style ... // tableLayoutPanel1.AutoScroll = true; This shrinks the TableLayoutPanel again when I reduce the height of a row. | | TaurusI76 Wednesday, September 16, 2009 10:18 AM |
|