0 Replies - 368 Views - Last Post: 10 December 2011 - 10:06 AM Rate Topic: -----

#1 VIPER5646  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 95
  • Joined: 01-March 09

Array List Not responding

Posted 10 December 2011 - 10:06 AM

Hi all

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()
        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"
        Dim cmd As New OleDb.OleDbCommand(Query, CFIConnection.con)
        cmd.CommandType = CommandType.Text
        cmd.CommandText = Query

        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
    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
            btnCustom.Enabled = True
            Dim JOBSearch As New JobAddress
            JOBSearch.Address = cbxSearch.SelectedItem.ToString
End Sub

Is This A Good Question/Topic? 0
  • +

Page 1 of 1