|
|
|
|
C++ ListBox Control.
The C++ System.Windows.Forms.ListBox control enables you to display a list of items from which the user can select one or multiple items from the list. The default is for the ListBox to list the items vertically however setting the multicolumn property to true the items are listed horizontally. The control is typically used to display data from a database. The items listed within the ListBox cannot be edited directly.
Namespace: System::Windows::Forms
System.Windows.Forms (in system.windows.forms.dll)
Creating an new C++ Windows forms ListBox.
ListBox^ listbox = gcnew ListBox;
Assigning a new location for the C++ Windows Forms ListBox.
listbox->Location = Point(40,40);
Assigning a Selection Mode value to the C++ ListBox control.
listbox->SelectionMode = System::Windows::Forms::SelectionMode::MultiExtended;
Adding a C++ ListBox control to the form.
Controls->Add(listbox);
Adding items to the C++ ListBox control.
String^ str = "DELL";
String^ str2 = "HP";
String^ str3 = "SONY";
listbox->Items->AddRange(gcnew cli::array<System::String^ >(3) {str, str2, str3});
Creating a Selected Index Changed Event for the C++ ListBox control.
this->listbox->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::listbox_SelectedIndexChanged);
Responding to the C++ ListBox Selected Index Changed event.
private: System::Void listbox_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
{
MessageBox::Show(listbox->SelectedItem->ToString());
}
|
|
|
|
|