Board index » delphi » HELP: Multiselect in Listbox

HELP: Multiselect in Listbox

Somebody already gave me the answer, but I lost it.   Anyhow, How do I get
what items are selected in a listbox when there are multiple items selected
(ie 10 items selected in listbox1).  I know I use the listbox1.selcount
command to get the total # of items selected, but how to I get each item?

 

Re:HELP: Multiselect in Listbox


Turn on the MultiSelect property.
then use the Listbox1.selected[x] property to see if a particular
element is selected.  The index is the same as the index of the listbox
items.  So you loop through all the items and test each one to see if it
is selected or not.

When you have a question like this, go to the Delphi help for that
component and examine lots of the properties and methods to learn about
it.  There are often examples in the help file as well.

Ryan Rife <rif2...@multipro.com> wrote in article
<34a1855...@news2.kcdata.com>...

Quote
> Somebody already gave me the answer, but I lost it.   Anyhow, How do I
get
> what items are selected in a listbox when there are multiple items
selected
> (ie 10 items selected in listbox1).  I know I use the listbox1.selcount
> command to get the total # of items selected, but how to I get each item?

Re:HELP: Multiselect in Listbox


const
        MAXITEMSSELECTED = 15; //or whatever you want for your maximum
var
      selitems:array[0..MAXITEMSSELECTED] of integer;
begin
      SendMessage(listbox1.handle,LB_GETSELITEMS,                
                   WPARAM(MAXITEMSSELECTED), @selitems);
end;    

The above code is off the top of my head so everything may not be exactly
right, but you get the idea. Just look up LB_GETSELITEMS in the help file
and all the parameters you need will be explained to you.  Windows
returns all the items selected in an array so you don't have to loop
through the whole list.

In article <01bd114f$e1787b60$d5629ecf@pdorcas>, pdor...@{*word*104}ramp.net
says...

Quote
> Turn on the MultiSelect property.
> then use the Listbox1.selected[x] property to see if a particular
> element is selected.  The index is the same as the index of the listbox
> items.  So you loop through all the items and test each one to see if it
> is selected or not.

> When you have a question like this, go to the Delphi help for that
> component and examine lots of the properties and methods to learn about
> it.  There are often examples in the help file as well.

> Ryan Rife <rif2...@multipro.com> wrote in article
> <34a1855...@news2.kcdata.com>...
> > Somebody already gave me the answer, but I lost it.   Anyhow, How do I
> get
> > what items are selected in a listbox when there are multiple items
> selected
> > (ie 10 items selected in listbox1).  I know I use the listbox1.selcount
> > command to get the total # of items selected, but how to I get each item?

Other Threads