Board index » delphi » Newbie question on Multiselect listbox

Newbie question on Multiselect listbox

Hi,

Rather than having a form with 60 checkboxes, I thought I could simplify
things by having a multiselect listbox.

however, there are some strings in the listbox that I want to disable.  
What I thought I could do is, when the user moves to a disabled item,
move him to the next valid component.  For example:

procedure Tform1.ListBox1Click(Sender: TObject);
var
  i: integer;
begin
  i := listbox1.itemindex;
  case i of
      3: listbox1.itemindex := 4;
     16: listbox1.itemindex := 20;
     20: listbox1.itemindex := 22;
  end;
end;

However, while I don't get any errors, and I can trade the code
executing, the itemindex doesn't change.

Can anyone provide a hint?

Thanks

 

Re:Newbie question on Multiselect listbox


Gerry,
  I don't know what is happening on your system, but here on mine (Delphi
3.01), your code works perfectly.
                                                      Dave

Quote
Gerry Forbes wrote in message <34FC8A43....@fox.nstn.ca>...
>Hi,

>Rather than having a form with 60 checkboxes, I thought I could simplify
>things by having a multiselect listbox.

>however, there are some strings in the listbox that I want to disable.
>What I thought I could do is, when the user moves to a disabled item,
>move him to the next valid component.  For example:

>procedure Tform1.ListBox1Click(Sender: TObject);
>var
>  i: integer;
>begin
>  i := listbox1.itemindex;
>  case i of
>      3: listbox1.itemindex := 4;
>     16: listbox1.itemindex := 20;
>     20: listbox1.itemindex := 22;
>  end;
>end;

>However, while I don't get any errors, and I can trade the code
>executing, the itemindex doesn't change.

>Can anyone provide a hint?

>Thanks

Re:Newbie question on Multiselect listbox


Dave -

Quote
>  I don't know what is happening on your system, but here on mine (Delphi
>3.01), your code works perfectly.

Until you try and move _up_ through the list.

Quote
>>procedure Tform1.ListBox1Click(Sender: TObject);
>>var
>>  i: integer;
>>begin
>>  i := listbox1.itemindex;
>>  case i of
>>      3: listbox1.itemindex := 4;
>>     16: listbox1.itemindex := 20;
>>     20: listbox1.itemindex := 22;
>>  end;
>>end;

--
Clayton Neff
Software Project Leader
The Personal Marketing Company, Inc.
11843 West 83rd Terrace
Lenexa, KS  66214
(913)492-0322
clay...@tpmco.com

Re:Newbie question on Multiselect listbox


In article <34FC8A43....@fox.nstn.ca>, Gerry Forbes <gfor...@fox.nstn.ca>
writes:

Quote
>However, while I don't get any errors, and I can trade the code
>executing, the itemindex doesn't change.

It functions as you want with mouse-clicks, but it will not with up arrow keys
(if you're auto-moving down) or down-arrow keys (if you're auto-moving up). If
you think about it this is what the code is doing.

You would be better setting the ItemIndex to -1 (ie un-selected) and doing a
check before using the selection. ie (using a set instead of a case statement)
. . .

with ListBox1 do
  if ItemIndex in [3, 16, 20] then
    ItemIndex := -1;

. . . then handle your selection with . . .

if ItemIndex > -1 then
   . . .handle your selection.

The other alternative is not to put the inadmissible selections in the listbox
in the first place. Or if you need to display them, put them in another
disabled listbox which has a BtnFace (grey) background. Or have one listbox and
owner-draw it with a BtnFace background for the inadmissibleitems _and_ set
ItemIndex to -1 (that would be my preferred user interface).

Hope this helps

Alan Lloyd
alangll...@aol.com

Other Threads