Only permitting items in the list

(YOU HAVE TO REMEMBER TO DO THIS TO BLOCK USER ENTERING THEIR OWN VALUES)

DropDownStyle = DropDownList (Only accepts strings that are part of the selection list)

Loading the contents of a comboBox at application startup


	cmbMyComboBox->BeginUpdate();
	cmbMyComboBox->SelectedIndex = -1;
	cmbMyComboBox->Items->Clear();		//Remove Existing Items If Necessary

	for (Count = 0; Count <= 500; Count++)	//Add Items
		cmbMyComboBox->Items->Add((Count * 100) + "mm");

	cmbMyComboBox->SelectedIndex = 0;	//Select default item
	cmbMyComboBox->EndUpdate();

	//while (cmbMyComboBox->Items->Count)	//Another method to remove items
	//	cmbMyComboBox->Items->RemoveAt(0);

Allowing User To Type Text To Find An Entry

DropDownStyle = DropDown
AutoCompleteMode = Append (or an alternative if preffered)
AutoCompleteSource = List Items
In this mode the user can enter text that doesn't match an entry in the list. You need to detect this yourself. Unfortunately you can't use the 'Leave' event of the combobox as if a user types the start of a name then uses tab to select it the SelectedIndex value is still -1 on the Leave call and only changes afterwards. You need to do the check using some other means.


	if (cmbUsername->SelectedIndex < 0)
		cmbUsername->Text = "";

Select An Item In the List


	cmbMyComboBox->SelectedIndex = 0;

Getting Currently Selected Item Text


	MyString = cmbMyComboBox->Items[cmbMyComboBox->SelectedIndex]->ToString();
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.