How to force MeasureItem in Owner Drawn Listbox?

  • Thread starter Thread starter Bugshake
  • Start date Start date
B

Bugshake

I have an owner drawn listbox which is derived from the ListBox class.

How can I force it to re-measure all items?

It doesn't use DataBinding (yet).

Thanks,
Stijn.
 
You could try forcing it to re-create it's handle.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Image transition effects, snap-to-grid and Layered Windows are
all discussed in May's edition of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
 
I really wouldn't know how to do that except for disposing and constructing
the listbox again. In that case, my current solution would be less drastic.
My current solution is:
- suspend layout
- remove all items
- add all items
- resume layout

In code (_table is a DataTable with the actual content of the items):
this.SuspendLayout();

int idx = this.SelectedIndex;

this.Items.Clear();

for( int i = 0; i < _table.Rows.Count; ++i )

{

this.Items.Add("");

}

this.SelectedIndex = idx;

this.ResumeLayout(true);
 
Hi Bugshake,

MeasureItem event is fired each time the list box is redrawn. Thus, all you
need to do is to force the list box to redraw itself. Call ListBox.Refresh
and this will raise MeasureItem event for each item in the list box.
 
Back
Top