Search the web
Sign In
New User? Sign Up
wtl · WTL support list
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
A little thought about ListView and TreeView's ItemData   Message List  
Reply | Forward Message #14196 of 16191 |

I saw almost all (kinda exaggerated) projects using
ListView and TreeView will store user data in ItemData.

The regular method is casting a pointer of the user
data to and from DWORD_PTR, then using the Get(Set)ItemData
to store/retrieve the casted pointer, like this

struct MyData
{
// user data
};

MyData *data = new MyData
listview.SetItemData(0, (DWORD_PTR)data);

.... in other place,

MyData *data2 = (MyData*)listview.GetItemData(0);

Could WTL add a new template parameter to CListViewCtrlT
like this:

template <class TBase, class TData=DWORD_PTR>
class CListViewCtrlT : public TBase
{
....
TData GetItemData(int nItem) const
{
....
}

BOOL SetItemData(int nItem, TData dwData)
{
....
}
...
}

then we can use CListViewCtrlT in this way:

CListViewCtrlT<CWindow,MyData*> listview;

MyData *data = new MyData
listview.SetItemData(0, data);

.... in other place,

MyData *data2 = listview.GetItemData(0);

Thus, no cast needed. How do you think about it?


Best Regards
gchen







Sat Jan 20, 2007 8:09 am

chengang31
Offline Offline
Send Email Send Email

Forward
Message #14196 of 16191 |
Expand Messages Author Sort by Date

I saw almost all (kinda exaggerated) projects using ListView and TreeView will store user data in ItemData. The regular method is casting a pointer of the user...
gchen
chengang31
Offline Send Email
Jan 20, 2007
8:10 am

Souds great to me! I hate castings all over the place....
Michelangelo Partipilo
mike2001ve
Offline Send Email
Jan 20, 2007
11:05 pm

Hi, ... I have smart classes of this kind for combo box and list view. WTL control class descendants are defined like this: CAiComboBoxT<CComboBoxItemData*>...
alax632
Online Now Send Email
Jan 20, 2007
11:13 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help