List Box With More Options

Need columns, colouring, icons etc? Use a List View

Creating a List Box

SelectionMode – Decide how many lines may be selected at a time by the user
MultiColumn – Not what you think! A multicolumn ListBox places items into as many columns as are needed to make vertical scrolling unnecessary.
Sorted – Allows the list to be automatically sorted
Text – Read to get currently selected item, write to cause it to move to matching item

Erasing the contents of a List Box


	lstMySelectOptions->Items->Clear();

Erasing Individual Items In A List Box


	while (lstMySelectOptions->Items->Count)
		lstMySelectOptions->Items->RemoveAt(0);	//(RemoveAt works on index number)

Adding items to a List Box


	lstMySelectOptions->BeginUpdate();		//Stop painting of the ListBox as items are added
	lstMySelectOptions->Items->Add("Item A");
	lstMySelectOptions->Items->Add("Item B");
	lstMySelectOptions->EndUpdate();

Getting Currently Selected Item


	if (lstMySelectOptions->SelectedIndex >= 0)		//Ensure a list item is selected (-1 if not)
	{
		UserId = lstMySelectOptions->SelectedIndex;

Selecting Items


   lstMySelectOptions->SetSelected(1, true);
   lstMySelectOptions->SetSelected(3, true);
   lstMySelectOptions->SetSelected(5, true);

Colouring Items

Use a ListView instead – gives full options over each item in the list.

Double Click

The double click point will be the current selectedindex


	private: System::Void lstResults_MouseDoubleClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e)
	{
		btnViewData_Click(this, gcnew EventArgs());
	}

 

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *