Clearing a Combo Box while Preserving the Selected Index

Feb 13 2006 9:30 PM
I currently have a combo box filling with data from an Access Database. This data is stored in an ArrayList which happens to be repopulated after the SelectedIndex is changed in the combo box. My remedy to removing items that are not part of the index is clearing all of the items from the combo box list but the problem is, when the list is cleared, so is the current item selected. My goal is to clear the list but preserve the selected data each time i change the item in the list so that you can see the last name selected. Any help is appreciated. Here is some code to hopefully give you some idea of what I want to do. //Portion that fills combo box. employeeInformation.Clear(); employeeNamecomboBox.Items.Clear() //label1.Text = employeeInformation.Count.ToString(); foreach (DataRow dtRow in dTable.Rows) { employeeNamecomboBox.Items.Add(dtRow["FirstOfNAME"].ToString() + " " + dtRow["SOCIAL_SECURITY_NUMBER"].ToString()); employeeInformation.Add((string)dtRow["SOCIAL_SECURITY_NUMBER"].ToString()); employeeInformation.TrimToSize(); } //Queries database for selected info, clears image list. private void employeeNamecomboBox_SelectedIndexChanged(object sender, EventArgs e) { imagelistBox.Items.Clear(); ConnectToAccess(employeeInformation[employeeNamecomboBox.SelectedIndex].ToString()); } if more code is needed to make my situation more clear I will gladly post it. Thanks again

Answers (1)