Board index » delphi » TListBox or TListView ?

TListBox or TListView ?

I have a feeling that this is a rather stupid question, but can
someone enlighten me on the essential difference between
TListBox and TListView?

That is: When should I use one and when the other?

I have discovered that in some of my programs I have used
either one or the other, apparently without any particular
reason for my choice.

regards Sven

 

Re:TListBox or TListView ?


Quote
>I have a feeling that this is a rather stupid question, but can
> someone enlighten me on the essential difference between
> TListBox and TListView?

> That is: When should I use one and when the other?

> I have discovered that in some of my programs I have used
> either one or the other, apparently without any particular
> reason for my choice.

Hi,

A TListBox is a very basic standard windows control
for displaying a list of strings, and selecting one
(or more) of them. It has built-in scrolling, and that's about it.

If you want to do anything even slightly more complicated than
just displaying a list of strings, then it is probably better
to use a TListView.
Using a listview, you can add icons for each item in the
list, add subitems to show a grid-like view of the data,
choose which of multiple views of the data to use (small icon,
large icon, report, etc). The listview is also a standard
windows component, and is used extensively in the
windows shell. Basically, it is *much* more customisable
than TListBox, but slightly more complicated to populate,
since you cannot just assign a stringlist to the items.

Cheers,

Chris

Re:TListBox or TListView ?


"Chris Morgan" <chris.nospam at lynxinfo.co.uk> wrote in message
news:450aab34$1@newsgroups.borland.com...

Quote
> >I have a feeling that this is a rather stupid question, but can
>> someone enlighten me on the essential difference between
>> TListBox and TListView?

>> That is: When should I use one and when the other?

>> I have discovered that in some of my programs I have used
>> either one or the other, apparently without any particular
>> reason for my choice.

> Hi,

> A TListBox is a very basic standard windows control
> for displaying a list of strings, and selecting one
> (or more) of them. It has built-in scrolling, and that's about it.

> If you want to do anything even slightly more complicated than
> just displaying a list of strings, then it is probably better
> to use a TListView.
> Using a listview, you can add icons for each item in the
> list, add subitems to show a grid-like view of the data,
> choose which of multiple views of the data to use (small icon,
> large icon, report, etc). The listview is also a standard
> windows component, and is used extensively in the
> windows shell. Basically, it is *much* more customisable
> than TListBox, but slightly more complicated to populate,
> since you cannot just assign a stringlist to the items.

> Cheers,

> Chris

Thanks!

I suppose then that when TListBox does the job I want then
TListBox is perfectly OK, and that an argument for using
TListView in such cases is mainly just standardisation?

regards Sven

Re:TListBox or TListView ?


Quote
> I suppose then that when TListBox does the job I want then
> TListBox is perfectly OK, and that an argument for using
> TListView in such cases is mainly just standardisation?

> regards Sven

Exactly.
Listviews normally look more modern.
But if you just want to display a list, then a listbox will do that.

cheers,

Chris

Re:TListBox or TListView ?


"Chris Morgan" <chris.nospam at lynxinfo.co.uk> wrote in message
news:450aab34$1@newsgroups.borland.com...

Quote
> Basically, it is *much* more customisable than TListBox, but
> slightly more complicated to populate, since you cannot just
> assign a stringlist to the items.

In a way you can.  If you use it in virtual mode, then there is nothing to
populate in the first place, and you can display the strings from your
TStringList directly.

Gambit

Re:TListBox or TListView ?


Quote
>> Basically, it is *much* more customisable than TListBox, but
>> slightly more complicated to populate, since you cannot just
>> assign a stringlist to the items.

> In a way you can.  If you use it in virtual mode, then there is nothing to
> populate in the first place, and you can display the strings from your
> TStringList directly.

But it is much more complicated to use a virtual list. You have to
implement a couple of event handlers etc. I said it was more
complicated; I didn't say it couldn't be done!

I hardly ever use listboxes, because listviews look much nicer.
I've not yet had to use a listview in virtual mode though.

Cheers,

Chris

Other Threads