Populating a Listbox

cmcrae

Member
Joined
Jan 21, 2003
Messages
10
I am trying to populate a listbox with the information from a column that is inside a table in my microsoft Access 2000 database. Also I was wondering how to delete a record from that same database..
 
If you are new to this like me, you may find it easier to populate the listbox at design time. I find it easier to bind the listbox to a dataset. I used the datasource property of the listbox. Im pretty sure that there are better ways, but this works for me.
 
This is an example of a dataset binding to a listbox

Code:
            Dim MyConn As New New OleDbConnection(<<CONNECTION STRING>>)
            MyConn.Open
            Dim MyAdapter As New OleDb.OleDbDataAdapter("SELECT * FROM TABLE", MyConn)
            Dim MyDataset As New DataSet()  Create dataset
            MyAdapter.Fill(MyDataset, "TABLE")  Fill dataset from adapter
            Listbox1.DataSource = MyDataset.Tables("TABLE")  Set the datasource of listbox
            Listbox1.DisplayMember = "FIELDNAME"  Set the field of the display column
            Listbox1.ValueMember = "ID"  Set the field of the ID field (Optional)
             Cleanup code
            MyDataset.Dispose
            LendersAD.Dispose

Thats for databinding Make sure you substitue your own connection string SQL and Fieldnames

Andy
 
Back
Top