Board index » cppbuilder » TListView Items

TListView Items


2006-06-10 04:05:39 AM
cppbuilder57
I'm having trouble understanding how to access individual TListItem on a
TListView.
I've added a bunch of items to a TListView using the code below, but when I
attempt to get the Count it only returns 1?
Code (lsvDrives is the TListView):
TListItem *lsiItem;
lsiItem = lsvDrives->Items->Add();
lsiItem->Caption = strDrive;
lsiItem->SubItems[0].Text = chrDriveInfo;
lsiItem->ImageIndex = 4;
Any reason why the lsvDrives->Items->Count is always 1?
Also, how do I access the Captions and SubItem text of each of the
TListItems?
Jeff
 
 

Re:TListView Items

"Jeff" < XXXX@XXXXX.COM >wrote in message
Quote
I've added a bunch of items to a TListView using the code below,
but when I attempt to get the Count it only returns 1?
Because you only added 1 item to begin with.
Quote
lsiItem->SubItems[0].Text = chrDriveInfo;
That is not correct. For starters, the SubItems is a TStrings, not an
array. You cannot use the '[]' operator on the SubItems property itself.
You need to use the Strings[] sub-property to access individual strings.
With that said, the SubItems property is initially empty, so you can't
access a substring that hasn't been added yet. You have to use the Add()
method instead, ie:
lsiItem->SubItems->Add(chrDriveInfo);
Quote
Also, how do I access the Captions and SubItem text of each
of the TListItems?
You already know the answer to that.
Gambit
 

Re:TListView Items

So when I populate the TListView I need to create new TListItem like this:
TListItem *lsiItem;
lsiItem = new TListItem;
lsiItem = lsvDrives->Items->Add();
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Jeff" < XXXX@XXXXX.COM >wrote in message
news:4489d492$ XXXX@XXXXX.COM ...

>I've added a bunch of items to a TListView using the code below,
>but when I attempt to get the Count it only returns 1?

Because you only added 1 item to begin with.

>lsiItem->SubItems[0].Text = chrDriveInfo;

That is not correct. For starters, the SubItems is a TStrings, not an
array. You cannot use the '[]' operator on the SubItems property itself.
You need to use the Strings[] sub-property to access individual strings.
With that said, the SubItems property is initially empty, so you can't
access a substring that hasn't been added yet. You have to use the Add()
method instead, ie:

lsiItem->SubItems->Add(chrDriveInfo);

>Also, how do I access the Captions and SubItem text of each
>of the TListItems?

You already know the answer to that.


Gambit


 

{smallsort}

Re:TListView Items

I guess I should have said that this code is in a for loop:
lsiItem = lsvDrives->Items->Add();
lsiItem->Caption = strDrive;
lsiItem->SubItems[0].Text = chrDriveInfo;
lsiItem->ImageIndex = 4;
Multiple items are showing up in the TListView, but when I read the
Items->Count is says 1.
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Jeff" < XXXX@XXXXX.COM >wrote in message
news:4489d492$ XXXX@XXXXX.COM ...

>I've added a bunch of items to a TListView using the code below,
>but when I attempt to get the Count it only returns 1?

Because you only added 1 item to begin with.

>lsiItem->SubItems[0].Text = chrDriveInfo;

That is not correct. For starters, the SubItems is a TStrings, not an
array. You cannot use the '[]' operator on the SubItems property itself.
You need to use the Strings[] sub-property to access individual strings.
With that said, the SubItems property is initially empty, so you can't
access a substring that hasn't been added yet. You have to use the Add()
method instead, ie:

lsiItem->SubItems->Add(chrDriveInfo);

>Also, how do I access the Captions and SubItem text of each
>of the TListItems?

You already know the answer to that.


Gambit


 

Re:TListView Items

"Jeff" < XXXX@XXXXX.COM >wrote in message
Quote
lsiItem = new TListItem;
Get rid of that. You do not create TListItem instances directly. Add()
will do that for you.
Gambit
 

Re:TListView Items

"Jeff" < XXXX@XXXXX.COM >wrote in message
Quote
I guess I should have said that this code is in a for loop:
Please show a more complee code snippet that actually compiles.
Quote
Multiple items are showing up in the TListView, but
when I read the Items->Count is says 1.
The only way that can happen is if you are actually adding only 1 item to
begin with.
Gambit