Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Populating a comboBox with an ArrayList

Populating a comboBox with an ArrayList

Scheduled Pinned Locked Moved Visual Basic
csharphelpannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    newbjohny
    wrote on last edited by
    #1

    Hi, I am trying to populate a ComboBox with the contents obtained within an ArrayList, but instead of putting the names held within the ArrayList, it writes "System.Collections.ArrayList" in the place of the desired names. Could you take a look at my code and see where I am going wrong. I am using vb.net 2002 version. Any help is greatly appreciated. Many thanks John This is the code for the function selectFieldNames :- Public fieldNames As New ArrayList() Public Function selectFieldNames(ByVal strSQL As String) As ArrayList ' select all field names from the selected table sqlite_cmd.CommandText = (strSQL) ' Now the SQLiteCommand object can give us a DataReader-Object: sqlite_datareader = sqlite_cmd.ExecuteReader() While sqlite_datareader.Read() Try fieldNames.Add(sqlite_datareader("name")) MessageBox.Show(sqlite_datareader("name")) Catch es As Exception MessageBox.Show(es.Message) End Try End While Return fieldNames End Function This is the code for populating the ComboBox :- Private Sub frmCreateIndex_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load dbConn.openExistingDatabse("Data Source=" & getDBName() & ";Version=3;New=False;Compress=True;") dbConn.createSQLCommand() Dim a As Integer Try dbConn.selectFieldNames("pragma table_info(test)") For a = 0 To (dbConn.fieldNames.Count) - 1 cmbFieldIndex.Items.Add(dbConn.fieldNames) Next a Catch es As Exception MessageBox.Show(es.Message) End Try End Sub

    D 1 Reply Last reply
    0
    • N newbjohny

      Hi, I am trying to populate a ComboBox with the contents obtained within an ArrayList, but instead of putting the names held within the ArrayList, it writes "System.Collections.ArrayList" in the place of the desired names. Could you take a look at my code and see where I am going wrong. I am using vb.net 2002 version. Any help is greatly appreciated. Many thanks John This is the code for the function selectFieldNames :- Public fieldNames As New ArrayList() Public Function selectFieldNames(ByVal strSQL As String) As ArrayList ' select all field names from the selected table sqlite_cmd.CommandText = (strSQL) ' Now the SQLiteCommand object can give us a DataReader-Object: sqlite_datareader = sqlite_cmd.ExecuteReader() While sqlite_datareader.Read() Try fieldNames.Add(sqlite_datareader("name")) MessageBox.Show(sqlite_datareader("name")) Catch es As Exception MessageBox.Show(es.Message) End Try End While Return fieldNames End Function This is the code for populating the ComboBox :- Private Sub frmCreateIndex_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load dbConn.openExistingDatabse("Data Source=" & getDBName() & ";Version=3;New=False;Compress=True;") dbConn.createSQLCommand() Dim a As Integer Try dbConn.selectFieldNames("pragma table_info(test)") For a = 0 To (dbConn.fieldNames.Count) - 1 cmbFieldIndex.Items.Add(dbConn.fieldNames) Next a Catch es As Exception MessageBox.Show(es.Message) End Try End Sub

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You setup an indexer to go through all the elements of fieldNames but you never used it to return an actual element in the array!

      Try
      dbConn.selectFieldNames("pragma table_info(test)")
      For a = 0 To (dbConn.fieldNames.Count) - 1
      cmbFieldIndex.Items.Add(dbConn.fieldNames)
      Next a
      Catch es As Exception
      MessageBox.Show(es.Message)
      End Try

      Should be:

      Try
      dbConn.selectFieldNames("pragma table_info(test)")
      For a = 0 To (dbConn.fieldNames.Count) - 1
      cmbFieldIndex.Items.Add(dbConn.fieldNames(a))
      Next a
      Catch es As Exception
      MessageBox.Show(es.Message)
      End Try

      Dave Kreskowiak Microsoft MVP - Visual Basic

      N 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You setup an indexer to go through all the elements of fieldNames but you never used it to return an actual element in the array!

        Try
        dbConn.selectFieldNames("pragma table_info(test)")
        For a = 0 To (dbConn.fieldNames.Count) - 1
        cmbFieldIndex.Items.Add(dbConn.fieldNames)
        Next a
        Catch es As Exception
        MessageBox.Show(es.Message)
        End Try

        Should be:

        Try
        dbConn.selectFieldNames("pragma table_info(test)")
        For a = 0 To (dbConn.fieldNames.Count) - 1
        cmbFieldIndex.Items.Add(dbConn.fieldNames(a))
        Next a
        Catch es As Exception
        MessageBox.Show(es.Message)
        End Try

        Dave Kreskowiak Microsoft MVP - Visual Basic

        N Offline
        N Offline
        newbjohny
        wrote on last edited by
        #3

        Hi, thanks for this, works a treat, I can't blieve I forgot to use the array. Thanks again John.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups