How to force MeasureItem in Owner Drawn Listbox?

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.
 
B

Bob Powell [MVP]

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
 
B

Bugshake

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);
 
S

Stoitcho Goutsev \(100\) [C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top