OnDropDown (C++)
Description
This example fills the list of a combo box with the set of open forms when you drop down the list. The list is regenerated every time the list is dropped down; if the application opens or closes forms, the combo box stays current.
Code
#include "Unit2.h"
#include "Unit3.h"
void __fastcall TForm1::ComboBox1DropDown(TObject *Sender)
{
ComboBox1->Items->BeginUpdate(); // Prevent repaints until done.
ComboBox1->Items->Clear(); // Empty the list of any old values.
for (int i = 0; i < Screen->CustomFormCount; i++)
{
if ((reinterpret_cast<TForm1 *>(Screen->CustomForms[i]))->Visible)
ComboBox1->Items->Add(Screen->CustomForms[i]->Caption); // Add form names.
}
ComboBox1->Items->EndUpdate(); //Re-enable painting.
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
ComboBox1->Sorted = True; // Make sure the form names are sorted.
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Form2->Show();
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Form3->Show();
}
Uses
- Vcl.StdCtrls.TCustomCombo.OnDropDown ( fr | de | ja )
- Vcl.StdCtrls.TCustomComboBox.Sorted ( fr | de | ja )
- System.Classes.TStrings.Clear ( fr | de | ja )
- System.Classes.TStrings.BeginUpdate ( fr | de | ja )
- System.Classes.TStrings.EndUpdate ( fr | de | ja )