Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
 
I implement a list box which has items with variable height, to calculate height of item i need to obtain data attached with it in MeasureItem().
 
Here is part of code inserting item in list box
 
INT idx = m_lstBox.AddString(strTxt);
m_lstBox.SetItemDataPtr(idx, pData);
 
Problem is that MeasureItem() function is called when the string is added, and at that time, data pointer is still not be set so i got bad pointer as result of GetItemDataPtr inside MeasureItem().
 
How can I set data pointer before MeasureItem call?
 
Quy
Posted 7-Jul-11 16:29pm
quyps837
Edited 7-Jul-11 16:30pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You can lock the window before adding items to it so that it will not redraw until your addition of items is complete:
 
m_lstBox.LockWindowUpdate();
int idx = m_lstBox.AddString(strTxt);
m_lstBox.SetItemDataPtr(idx, pData);
m_lstBox.UnlockWindowUpdate();
  Permalink  
Comments
Marcus Kramer at 8-Jul-11 10:23am
   
Excellent solution. I forgot about that.
quyps at 11-Jul-11 22:06pm
   
I totally agree with Marcus. 5*!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Are you sure you don't want to finish adding all the items, then perform an UpdateData so that the list item actually gets created first before you try to measure it?
I'm not 100% this would work as I haven't been in MFC for the last 6 months, but this did ring a bell.
  Permalink  
Comments
quyps at 8-Jul-11 0:01am
   
thanks Marcus! I have had a same thought. But there is another issue: how to know in MeasureItem() that it is called from AddItem() or UpdateData.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.150302.1 | Last Updated 8 Jul 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100