Recent

Author Topic: [SOLVED]ListBox Not Selecting Text When Clicking On Up/Down Arrow Control  (Read 5073 times)

Knipfty

  • Full Member
  • ***
  • Posts: 232
Hi All,

I created a ListBox on a Panel within a Form.  It contains 3 values in the string list.

When I just click on the little up/down arrows and not the text in the ListBox, no event handler is triggered.  I can see this because the highlight color within the List Box does not change until I actually click on the text within the ListBox.

I have the following events all pointing to the same event handler:
onChange
OnChangeBounds
OnClick
OnEnter
Onexit
OnResize

It almost as if the up/down control needs its own event handler, but I don't see one.

In case it helps, the following properties are set at design time:
ClickOnSelChange=true
ExtendedSelect = true
MultiSelect = false

I've tried turning them off individually to no avail...

Thanks
« Last Edit: August 05, 2012, 02:11:58 pm by Knipfty »
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 728
Re: ListBox Not Selecting Text When Clicking On Up/Down Arrow Control
« Reply #1 on: August 04, 2012, 08:33:16 pm »
I think the little up and down arrows on the listbox are only meant to scroll the items visible in the box knipfty.   They don't generate any external events. 

This is the way they work here -- I don't get any events either:  only the scrolling action.  (I'm using WinXP and Lazarus 0.9.30.4).   

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: ListBox Not Selecting Text When Clicking On Up/Down Arrow Control
« Reply #2 on: August 05, 2012, 12:53:51 am »
The arrows on a listbox scrollbar are designed for scrolling into view the hidden part of an item list that is too long for every item to be fully visible.
To change the listbox selection using visual arrows you need an external UpDown control (the 7th control on the Common Controls tab of the Component Palette).
Drop it near a listbox, and set its Associate property to the listbox. Double-click the UpDown's OnClick event and add this code

Code: [Select]
procedure TForm1.UpDown1Click(Sender: TObject; Button: TUDBtnType);
begin
  if (ListBox1.Items.Count < 2) or (ListBox1.ItemIndex < 0) then Exit;
  case Button of
   btNext: if (ListBox1.ItemIndex > 0)
             then ListBox1.ItemIndex := ListBox1.ItemIndex - 1;
   btPrev: if (ListBox1.ItemIndex < ListBox1.Items.Count - 1)
             then ListBox1.ItemIndex := ListBox1.ItemIndex + 1;
  end;
end;     

Howard

Knipfty

  • Full Member
  • ***
  • Posts: 232
Re: ListBox Not Selecting Text When Clicking On Up/Down Arrow Control
« Reply #3 on: August 05, 2012, 01:31:06 pm »
Thanks Curt as you have confirmed my observation.  At least now I know its not something I am doing.

howard, I never considered adding another control next to the one I am already using.  Thanks for thinking outside the box.  Right now I trying to figure out if I should use your suggestion or convert the the control to a radio box since there are only 3 items.

Knipfty
64-bit Lazarus 2.2.0 FPC 3.2.2, 64-bit Win 11

 

TinyPortal © 2005-2018