Board index » cppbuilder » Check which item in CheckListBox is checked

Check which item in CheckListBox is checked

Hi,

I am new to Borland C++. I have a checklistbox and I want to know which item
in it is checked and highlighted when I use the OnDoubleClick function.
Thank you in advance.
Please advice.

 

Re:Check which item in CheckListBox is checked


GUI,

Quote
> I have a checklistbox and I want to know which item in it is
> checked and highlighted when I use the OnDoubleClick function.

The TCheckListBox::ItemIndex and Checked[] properties will help you out
here...

void __fastcall TForm1::CheckListBox1DblClick(TObject *Sender)
{
  // grab the index of the selected item
  const int selected_item_index = CheckListBox1->ItemIndex;

  // if an item is selected
  if (selected_item_index != -1)
  {
    // grab the caption of the selected item
    const AnsiString selected_item_caption(
      CheckListBox1->Items->Strings[selected_item_index]
      );
    ShowMessage(selected_item_caption + " is selected.");

    // determine if the selected item is checked
    const bool is_item_checked =
      CheckListBox1->Checked[selected_item_index];
    if (is_item_checked)
    {
      ShowMessage(selected_item_caption + " is checked.");
    }
    else
    {
      ShowMessage(selected_item_caption + " is not checked.");
    }
  }

Quote
}

Good luck,
--
Damon C. <TeamB>
http://www.bcbcaq.com
http://graphicsbb.itgo.com

Other Threads