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 Sub
VB 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
Thanks JMC...the problem is that the number of Districts is not static, it increases and decreases with time.At one time it can be 60 and at another time it can be 56 Districts.
And i want to find the combo item using the District text that is displayed in the combo.(I know this sounds contradictory to the thread title)
This is how i populate my District Combobox, DistID is hidden and District is shown.
VB Code:
Sub PopulateDistrictCombo()
Dim strSQL As String = "SELECT DistID,District FROM tblDistricts ORDER BY District ASC"
I see this is what your code does.
but after populating the combobox, i populate the combobox with a District within
a record i want to update. So, i would like to use the "District Text" to basically bring up the District with the same name
from the district items contained in the combobox.This will inturn bring up the hidden ID with the district and i would use it
to populate another combobox in the SelectedIndexChanged of the district combobox