WynApse Home Page
Home    Blog    Contact       
Latest Article:
Read my CoDe Magazine Article
My Tags:
Hosted by:


3 Months FREE!

Ask me how to get 6 months free.


Lifetime Member:


web tracker

Over 3200671 Pages Served


Custom CListBox Control


Download the source code

Once again I am regenerating an article I wrote in the spring of 1999. To prove it's relevance, I rebuilt the project in VS2005. The CListControl still behaves as it did way back then, and my solution to the problem still holds.

The Need

The problem this article resolves is what happens when we transition from Figure 1 to Figure 2 by adding just one row of data to the CListControl:

Figure 1Figure 2
We spend a lot of time calculating the width of our (hopefully) longest line of text in the CListBox, and then when another row gets added, scrollbars appear and our text disappears into the right border.

If you logically go into the dialog resource and under Styles, select 'Horizontal Scroll' and rebuild, you'll notice that the horizontal scroll bar does not appear. Checking "Disable no scroll" does put up a grayed horizontal scroll bar, but this also messes with the handling of the vertical. The combination taken here was turn off the "Disable no scroll", but leave Horizontal scroll checked.

For an individual use with a fixed data list, a one-off solution to all this might be acceptable, but I've taken the route of providing a single solution that can be used in any situation and provide clean-looking ListBox data regardless of line length or number of rows.

Download the code using the link above, and read on to see the explanation.

For those familiar with 'Text Extents' and 'Horizontal Extents', don't think you know all about this situation without checking out the code!

Go to Page 2

RSS:  rss URL

Microsoft MVP

Member of WPF and Silverlight Insiders

Creative Commons License
Check out our book:
Our Book
Advertise on this site through Lake Quincy Media
Copyright © 2006-2010, WynApse