Board index » cppbuilder » Listview data property

Listview data property


2003-07-14 06:33:59 AM
cppbuilder89
How do you add an integer value to the data property of
a listview, then delete it when you destroy the listview?
Thanks.
 
 

Re:Listview data property

Greg Stantin wrote:
Quote
How do you add an integer value to the data property of
a listview, then delete it when you destroy the listview?

Thanks.
Couple of ways:
example with a struct:
TListItem *MyItem=ListView1->Items->Add();
struct MyStruct {
int a;
} *x;
MyItem->Caption="Caption 1";
x=new struct MyStruct;
x->a=23;
MyItem->Data=x;
// note that since operator new is used to allocate the struct, then
operator delete should be used to free the allocation before the
ListView1->Items->Clear() method were called.
//-----------------example with a simple data type
TListItem *MyItem=ListView1->Items->Add();
MyItem->Data=(void *)23; // just typecast a simple type (must be sizeof
void * or less in length)
HTH
keith