DropdownList error - Cannot have multiple items selected in a dropdownlist

fouzwerg

Member
Joined
Feb 24, 2006
Messages
6
Programming Experience
3-5
Hi,

I have a dropdown and a listbox. The dropdown is used to populate the listbox by inserting values after the current listitem. After an insertion, I wish the dropdown to reset back to the top selection and the selection in the listbox to highlight the recently added field.

For a complete listing of my code refer below, but for some reason I get this error 'Cannot have multple items selected in a DropDownList' when i'm trying to set the selectedIndex for the listbox as in the code directly below.

dropdown.selectedIndex = 0
listbox.selectedIndex = index + 1

Also, for some strange reason if i reverse the order of the above two lines, the error does not come up but the listbox's index = -1 for some reason. Can anyone help?

Is my listbox connected to the dropdownlist some how and if so how do I change this?

I am not changing the selection directly through the items collection, always only using selectedindex.


Code:
Dim index As Integer = listbox.SelectedIndex
Dim Li As New ListItem
Li = ListDc.Items.FindByValue(dropdownlist.SelectedItem.Value)

If Li Is Nothing Then

If index = -1 Then
ListDc.Items.Add(dropdownlist.SelectedItem)
Else
ListDc.Items.Insert(index + 1, SelectList.SelectedItem)
End If
End If

Else
ShowMessage(ListMessage, "Cannot insert duplicate entries", "Error")
Return False
End If

dropdownlist.SelectedIndex = 0
ListDc.SelectedIndex = index + 1

Return True
End Function
 
Back
Top