Dynamic SplitterDistance

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

My goal is to dynamically adjust a SplitContainer's vertical split
between a directory TreeView on the left and a detailed file ListView
on the right.

The code is working but does not initialize correctly.

Rough Method >>

1) Autosize columns by setting widths = -1.
2) Clear items from list.
3) Fill list.
4) SplitterDistance = Form.ActiveForm.Width - 32 -
list.SumColumnWidths;

The "32" above is a trial and error factor that compensates for the
widths of the sizing borders, right scroll bar, and splitter width.
This technique works great AFTER the first screen is loaded. The
ListView has no extra space off to the right and 100% of the right
most column is visible. Thus the TreeView has maximum space and
produces a scroll bar if needed. The alignments stays sharp even upon
changing font sizes that force row height changes. It is slick!

Here is the root of the problem >>

At the end of the Form's constructor I placed print statements to echo
the column widths. They are all -1. Not until exiting the constructor
are the autosized columns' width property available for the
calculation. Thus the first screen splitter is not placed accurately.

This challenge is more about learning about objects than it is to just
make that first screen "pretty".

I've tried SuspendLayout() and various other guesses ... but obviously
no success.

Thanks for any help.

-- Tom
 
Tom, how about setting SplitterDistance in the form's Shown() event
handler? That should work.

Michael
 
Michael -- THANK YOU !!

Your suggestion was **PERFECT** !!

I was unfamiliar with the Shown() method. In less than 10 minutes I
was able to get it working.

I wish my thank you could brighten your day as much as my day has been
brightened by your help. :)

This newsgroup rocks! Every_Single_Time I have posted here someone has
understood my predicament and set me on the right path. Awesome!

-- Tom

p.s. I replied previously and got some kind of authorization failure
to delivery bomb. I refreshed and did not see my previous attempt ...
so here I try again. If both show up ... my apologies for double
posting.
 
Back
Top