Results 1 to 4 of 4

Thread: Find Combo Item By ID and Reset SelectedIndex

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2006
    Posts
    426

    Find Combo Item By ID and Reset SelectedIndex

    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:
    1. Sub getDistValueByID()
    2.        Dim strSQL As String = "SELECT DistID FROM tblDistricts WHERE(District='" & Me.cbDistrict.Text & "')"
    3.         Dim strID As String = connMger.LookUp(strSQL)
    4.         FindComboItemByID(Me.cbDistrict, strID)
    5.     End Sub
    VB Code:
    1. Public Sub FindComboItemByID(ByVal cbName As ComboBox, ByVal strID As String)
    2.         ' This sub is used to find an Item in a combobox/listbox and
    3.         ' set the selected index of the combo box/listbox to that item
    4.         'On Error Resume Next
    5.         Dim bFound As Boolean
    6.         Dim itemCount As Integer
    7.         Dim lstItem As New ListItem
    8.         itemCount = 0
    9.         While Not bFound Or itemCount <= cbName.Items.Count - 1
    10.             lstItem = CType(cbName.Items(itemCount), ListItem)
    11.             If lstItem.ID = CInt(strID) Then
    12.                 cbName.SelectedIndex = itemCount
    13.                 bFound = True
    14.             End If
    15.             itemCount += 1
    16.         End While
    17.         If Not bFound Then
    18.             cbName.SelectedIndex = -1
    19.         End If
    20.     End Sub
    Attached Images Attached Images  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width