Board index » cppbuilder » Combobox with chech box in drop down list

Combobox with chech box in drop down list

How can I insert check box in a combo box list?
I suppose it's possible but I don't know how to do it
I've always written single component modifying its behaviour
Thanks in advance
Andrea
 

Re:Combobox with chech box in drop down list


Quote
"andrea" <andrea.ciampolini....@tiscalinet.it> wrote in message

news:3eaa5527@newsgroups.borland.com...

Quote
> How can I insert check box in a combo box list?

You can't, at least not with actual TCheckBox instances.  You'll have to
just use the TComboBox's OnDrawItem event to manually draw images of
checkboxes for each item, such as via the Win32 API DrawFrameControl()
function.  That won't allow you to actually click on them and toggle them
while tey are being displayed, though.  ComboBox controls don't provide for
detecting clicks inside of items of the drop-down menu.  Unless you do some
lower-level subclassing of the actual ListBox used for the menu, I suppose.

Gambit

Re:Combobox with chech box in drop down list


The best would be to to mix those two components. ... it shouldn't be hard

Re:Combobox with chech box in drop down list


Quote
"SHADOW-XIII" <_sha...@onet.pl> wrote in message

news:3eac2dae@newsgroups.borland.com...

Quote
> The best would be to to mix those two components. ...
> it shouldn't be hard

Actually, it would be harder than you think...

Gambit

Re:Combobox with chech box in drop down list


If you replace the following two lines

    ComboBox1->Enabled = false;
    ComboBox1->Enabled = true;

in the ComboBox1DropDown() event handler

with

    ComboBox1->Style = csSimple;
    ComboBox1->Style = csDropDownList;
    ComboBox1->Update();

You wont get the drop down menu from the ComboBox, so that the only
"DropDown List" will be the ChecklistBox. That should give a better
behaviour.

Rodolfo
Stargate

Re:Combobox with chech box in drop down list


This a a method that needs some polish, however you'll get something close
to what you want. (Some font and font sizes will need some adjustment)
Also the drop down list is visible for a short period of time (less 1S) but
if that bothers you can intercept the message and stop it.

TCheckListBox* CheckListBox1;
TComboBox* ComboBox1;

//--------------------------------------------------------------------------
-
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
    Width = 800;
    Height = 600;
    Position = poScreenCenter;

    // Create a CheckListBox Control
    CheckListBox1 = new TCheckListBox(this);
    CheckListBox1->Parent = this;
    CheckListBox1->Top = 20;
    CheckListBox1->Left = 20;
    CheckListBox1->Width = 365;
    CheckListBox1->Font->Name = "Times New Roman";
    CheckListBox1->Font->Height = 20;
    CheckListBox1->Height = CheckListBox1->Font->Height;

    // Create a ComboBox Control
    ComboBox1 = new TComboBox(this);
    ComboBox1->Parent = this;
    ComboBox1->Top = CheckListBox1->Top;
    ComboBox1->Width = 20;
    ComboBox1->Height = CheckListBox1->Font->Height + 2;
    ComboBox1->Left   = CheckListBox1->Left +
                        CheckListBox1->Width - ComboBox1->Width;
    ComboBox1->OnDropDown = ComboBox1DropDown;

    // Add some items
    for (int i = 1; i <= 30; i++)
        CheckListBox1->Items->Add("Item " + String(i));

Quote
}

//--------------------------------------------------------------------------
-

void __fastcall TForm1::ComboBox1DropDown(TObject *Sender)
{
    ComboBox1->Enabled = false;
    ComboBox1->Enabled = true;
    static bool Toggle = false;

    if (Toggle)
    {
        CheckListBox1->Height = CheckListBox1->Font->Height;
        Toggle = false;
    }
    else
    {
        CheckListBox1->Height = (CheckListBox1->Font->Height*
                                CheckListBox1->Items->Count) + 5;
        Toggle = true;
    }

Quote
}

Rodolfo
StarCinema
http://members.optusnet.com.au/~rodolfofrino/
From StarGate

Quote
"andrea" <andrea.ciampolini....@tiscalinet.it> wrote in message

news:3eaa5527@newsgroups.borland.com...
Quote
> How can I insert check box in a combo box list?
> I suppose it's possible but I don't know how to do it
> I've always written single component modifying its behaviour
> Thanks in advance
> Andrea

Re:Combobox with chech box in drop down list


"StarCinema - Rodolfo Frino" <starcin...@stargate.com> wrote in message
news:3eacb8d4@newsgroups.borland.com...

Quote
> This a a method that needs some polish, however you'll
> get something close to what you want.

If you're going to go that route, then it would be better to make a new
component out of it, where the component is derived from TComboBox and
intercepts all of the various combobox messages that have anything to do
with the drop-down list, and then redirects all of the work to its own
custom ListBox control internally instead of using the native list provided
by the OS.  There is a section in the Win32 API titled "Default Combo Box
Behavior" that lists all of the messages (amongst others) that would have to
be intercepted and handled manually, and how they are meant to interact with
the ListBox control actually used.

Gambit

Other Threads