Click here to Skip to main content
13,001,686 members (63,836 online)
Click here to Skip to main content
Add your own
alternative version


37 bookmarked
Posted 26 Jan 2004

Resizable ListBox

, 26 Jan 2004
Rate this:
Please Sign up or sign in to vote.
A standard ListBox redrawing correctly when it is resized.


You know that ListBox is a very useful component for displaying your style list with ownerdraw method. If you are using VariableSize mode to draw ListBox item, I think it will be interesting to you. All works fine if you are not going to change a ListBox's horizontal size. When you try to change ListBox's horizontal size, ListBox calls Draw for each visible item again, but problem is that it is not calling MeasureItems and your ListBox does not look like as you want..


The MeasureItem event is raised when you add a new item to the list. So it occurs only once for each item. I have not found any direct way to call MeasureItem forcedly.

There are some indirect ways to solve this problem.

One of them is full reimplementation of ListBox control. See in the article "An auto-resize C# ListBox" By Christian Tratz.

The second way is to remove all items and add them again; as a result MeasureItems will be recalled for each item again. But if you have many items in your ListBox, this way is not the best one. You may have performance problems.

My solution is that when you need ReMeasuringItem, call code like this:

//  Forced Call MeasureItems.
listBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
listBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;

Using the code

Do not put this code in the ListBox resizing event. It will not work. Put it in ListBox's parent control. In my example, I put it in a form's event. For better performance, you may put it in SizeChanged event.

P.S. In my example, I demonstrate resizing ListBox by this way. In your code, you may wait until the form is resized and then allow to redraw ListBox items. Using this way, you will have better performance.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Irakli Lomidze
Web Developer
Georgia Georgia
I'm 28 My Name is Irakli Lomidze.
I Have 12 Year Exrperiense Development Software under Microsoft.

Desktop Application, Two and Multi tier Application with a rich interface on the client side.

Security Application, Including Cryptography Services for Enterprise Network Users.

You may also be interested in...

Comments and Discussions

GeneralMouse Events Pin
imran_shahid@msn.com25-Sep-07 19:17
memberimran_shahid@msn.com25-Sep-07 19:17 
QuestionAuto Scroll to Bottom Pin
crjackso12-Jun-07 7:47
membercrjackso12-Jun-07 7:47 
Generaljust call LB_SETITEMHEIGHT Pin
Eugene Polonsky11-Mar-06 6:54
memberEugene Polonsky11-Mar-06 6:54 
GeneralLarge Text.. Pin
HyperX12-Nov-05 19:16
memberHyperX12-Nov-05 19:16 
GeneralRe: Large Text.. Pin
alex143427-Jun-06 16:42
memberalex143427-Jun-06 16:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 27 Jan 2004
Article Copyright 2004 by Irakli Lomidze
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid