I'm trying to dynamically report the number of items currently selected in a
list box.
I can't seem to find an event that fires as the selection is changing.
I've tried mouseup/mousemoving/mousedown/ondrag.
I've tried capturing the mouse.
I've tried setting dragimmediate to true.
Nothing I've done causes any events to fire until after the mouse button is
released. (and when it is first clicked)
Thanks!
-pete
Use the listbox's OnClick event:
procedure TForm1.ListBox1Click(Sender: TObject);
begin
// Make sure MultiSelect and ExtendedSelect are true.
StatusBar1.SimpleText := IntToStr(ListBox1.SelCount);
end;
HTH,
Chris.
---------------
Thanks for the response.
I am doing just that. Now, I'm using a static control, not a status bar...
When I click and drag to select multiple items, all of that works, except
the number of items selected doesn't refresh until I let go of the mouse.
any thoughts?
-pete
"Chris R. Timmons" <ctim...@NOSPAMlgrs.com> wrote in message
news:Xns90F68BACB24A...@207.105.83.65...
Thanks Chris, for sending me in the right direction... (if a status bar
worked....)
-pete
"Pete d'Oronzio" <myfir...@pdmagic.com> wrote in message
news:3b706858$1_2@dnews...
-pete
"Pete d'Oronzio" <myfir...@pdmagic.com> wrote in message
news:3b707271_2@dnews...
> Scratch that, it still doesn't work. The update works when the
> list box is filling, but not when I'm dragging the mouse to
> select items.
Pete,
I see your point. I can't get it to work that way either. I tried
setting Style to lbOwnerDrawFixed, and creating a custom OnDrawItem
event that updated the status bar for each item drawn. That didn't
work.
The TListbox control is a Delphi wrapper for the Windows-supplied
Listbox control. It's possible that there is no way to make Listbox
do what you want. You may have to try a third-party listbox
component that is not tied to the Windows listbox control.
HTH,
Chris.
---------------
That sounds plausable... But...
I could swear I've done this in 3.1 apps. If I know the message that I am
looking for, how would I trap that using Delphi / VCL?
Here's the message I'd like to receive, that I believe is being sent:
-pete
LBN_SELCHANGE (2.x)
LBN_SELCHANGE
The LBN_SELCHANGE notification message is sent when the selection in a list
box is about to change. The parent window of the list box receives
this notification message through a WM_COMMAND message.
Parameter Description
wParam Specifies the identifier of the list box.
lParam Specifies the handle of the list box in the low-order word, and
specifies the LBN_SELCHANGE notification message in the high-order
word.
Comments
This notification is not sent if the selection is changed by the
LB_SETCURSEL message.
This notification applies only to a list box that has the LBS_NOTIFY style.
The LBN_SELCHANGE notification is sent for a multiple-selection list box
whenever the user presses an arrow key, even if the selection does not
change.
See Also
LBN_DBLCLK
LBN_SELCANCEL
LB_SETCURSEL
WM_COMMAND
Notification messages (3.1)
"Chris R. Timmons" <ctim...@NOSPAMlgrs.com> wrote in message
news:Xns90F7A499AA34...@207.105.83.65...
TCustomListbox already traps LBN_SELCHANGE in
TCustomListBox.CNCommand (in StdCtrls.pas):
// From Delphi 5.01.
procedure TCustomListBox.CNCommand(var Message: TWMCommand);
begin
case Message.NotifyCode of
LBN_SELCHANGE:
begin
inherited Changed;
Click;
end;
LBN_DBLCLK: DblClick;
end;
end;
It looks like the Changed and Click events are being called for every
LBN_SELCHANGE notification. Since putting your code in a listbox's
OnClick event didn't work, I'm guessing that writing a custom
component derived from TCustomListBox and trapping LBN_SELCHANGE
won't work either (but that's just a guess).
There may be some other Windows message(s) you could trap, but I
don't know them off the top of my head. You might try re-asking this
question in the vcl.writing group. I'm sure the VCL wizards there
can give you far more help about writing VCL components than I can.
HTH,
Chris.
---------------