Hello Folks i want to get ID of the combobox item and then reset the selected index of that combobox to that item. I populate my Combobox with a list of 56 Districts from an array so, the ID is hidden.
When i call the sub below which calls FindComboItemByID it gives me the error below, so the sub FindComboItemByID has some problem that i seem not to figure out...is there a better way of doing this?
VB Code:
Sub getDistValueByID() Dim strSQL As String = "SELECT DistID FROM tblDistricts WHERE(District='" & Me.cbDistrict.Text & "')" Dim strID As String = connMger.LookUp(strSQL) FindComboItemByID(Me.cbDistrict, strID) End SubVB Code:
Public Sub FindComboItemByID(ByVal cbName As ComboBox, ByVal strID As String) ' This sub is used to find an Item in a combobox/listbox and ' set the selected index of the combo box/listbox to that item 'On Error Resume Next Dim bFound As Boolean Dim itemCount As Integer Dim lstItem As New ListItem itemCount = 0 While Not bFound Or itemCount <= cbName.Items.Count - 1 lstItem = CType(cbName.Items(itemCount), ListItem) If lstItem.ID = CInt(strID) Then cbName.SelectedIndex = itemCount bFound = True End If itemCount += 1 End While If Not bFound Then cbName.SelectedIndex = -1 End If End Sub




Reply With Quote