Board index » cppbuilder » Item selected event in TListBox / TCheckListBox

Item selected event in TListBox / TCheckListBox

Thanks for the answer, but that's not what I'm looking for. OnClickCheck
only occurs when the user changes the check mark, whereus I need to know
when the user selects another element in the list. Anyone?
 

Re:Item selected event in TListBox / TCheckListBox


There are two ways to do that:

1) Use the OnClick event and test the ItemIndex property to see if it's
changed:

void __fastcall TForm1::CheckListBox1Click(TObject *Sender)
{
    static int LastIndex = -1;
    if(CheckListBox1->ItemIndex != LastIndex)
    {
        // index has been changed, do something

        // remember the new index
        LastIndex = CheckListBox1->ItemIndex;
    }

Quote
}

2) Subclass the TCheckListBox and catch the LBN_SELCHANGE notification

TWndMethod OldWndProc;

__fastcall TForm1::TForm1(TComponent *Owner)
    : TForm(Owner)
{
    OldWndProc = CheckListBox1->WindowProc;
    CheckListBox1->WindowProc = MyWndProc;

Quote
}

void __fastcall TForm1::MyWndProc(TMessage &Message)
{
    // pass the message to the original for default processing
    OldWndProc(Message);

    if((Message.Msg == CM_COMMAND) && (HIWORD(Message.WParam) ==
LBN_SELCHANGE))
    {
        // the selection hs changed, do something
    }

Quote
}

Gambit

Quote
"jbeulgrel" <tom_...@hotmail.com> wrote in message

news:3BCD36E4.2090203@hotmail.com...
Quote
> Thanks for the answer, but that's not what I'm looking for. OnClickCheck
> only occurs when the user changes the check mark, whereus I need to know
> when the user selects another element in the list. Anyone?

Other Threads