I have two arraylists. The JobArraylist gets adresses from a database table and JobIDArray Gets the ID for those addresses.
I'm populating a Combobox with the JobArrayList which is working ok.
When I select a an address in the combobox I use the sectectindex to get the AdressID from JobIDArray.
My Issue is when I have duplicate addresses the JobIDArray always returns the the ID for the last Address. not the select one.
Thank you
this code gets data from the database and populates the Combobox.
Private Sub PopulateSearch()
cbxSearch.Items.Clear()
Dim JobArraylist As New ArrayList
Dim Query As String = "SELECT JobID,JobAddress FROM JobName_tbl Order by JobAddress"
Dim CFIConnection As New Connection
CFIConnection.FilePath = "C:\CFI\FilePath.Txt"
CFIConnection.connect()
Dim cmd As New OleDb.OleDbCommand(Query, CFIConnection.con)
cmd.CommandType = CommandType.Text
cmd.CommandText = Query
CFIConnection.con.Open()
Dim dr As OleDb.OleDbDataReader
dr = cmd.ExecuteReader
While dr.Read
If Not dr.IsDBNull(1) Then
JobArraylist.Add(dr.GetString(1)) ' arraylist will be used to populate combobox
JobIDArray.Add(dr.GetInt32(0)) 'When the Selected Item on the Combobox is Selected it gets the Item ID
End If
End While
For Each Job In JobArraylist
cbxSearch.Items.Add(Job)
Next
dr.Close()
CFIConnection.con.Close()
End Sub
This Code gets the ID for the selected Address.
Private Sub cbxSearch_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxSearch.SelectedIndexChanged
Dim x As Integer = cbxSearch.SelectedIndex
If cbxSearch.SelectedItem IsNot Nothing Then
NewCustomerID = CInt(JobIDArray.Item(x))
GridLoad = True
UpdateAddress = True
btnAddJob.Enabled = False
LoadListGroup()
btnCustom.Enabled = True
Dim JOBSearch As New JobAddress
JOBSearch.Address = cbxSearch.SelectedItem.ToString
JOBSearch.NewSearch()
End Sub