[RESOLVED] Populating a comboBox with an ArrayList
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 :-
Code:
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 :-
Code:
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
Re: Populating a comboBox with an ArrayList
Because dbConn.fieldNames returns the ArrayList object as a whole. You need to add
dbConn.fieldNames(a).ToString()
to the combobox.
Re: Populating a comboBox with an ArrayList
Hiya, sorry for the delay in replying, hope internet been cut off. Many thanks for your help, works fine now.
Thanks again
John