Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a Access Table into a ListBox 2

Status
Not open for further replies.

DaveRussell

Programmer
Jul 31, 2003
22
CA
Hello, first i'd like to say that this place is great! i haven't had to post yet, because i've been able to find some very helpful solutions. Except....

i have 2 listboxes on a form. The first contains a list of General Options that will appear on a report. The second is a MultiSimple Listbox that i would like to display the customizeable details connected to the selected General Option.

I have the first box working, however, i'm having troubles with the second. I can fill a datagrid, but not a listbox... what would be the appropriate way of doing that programatically?

thanks so much!

Dave.
 

Will you be filling second ListBox control with data from a datasource (database)???

If yes, then the following sample shows you how to bind ListBox control with datasource.

Dim selectString As String
Dim objDA As OleDbDataAdapter
Dim objDS As New DataSet()

Try
'Initialize SQL string.
'Change the SQL string as per your requirememnt
selectString = "SELECT Field1, Field2 FROM TableName " & _
"WHERE xxxx " & _
"ORDER BY Field2"

'Initialize the OleDbDataAdapter with SQL String & Connection String.
objDA = New OleDbDataAdapter(selectString, connectionString)
'Fill the DataSet object with data.
objDA.Fill(objDS, "TableName")

'Bind the CheckList control to DataSet object.
chklstAssigned.DataSource = objDS.Tables("TableName")
chklstAssigned.ValueMember = objDS.Tables("TableName").Columns(0).ToString
chklstAssigned.DisplayMember = objDS.Tables("TableName").Columns(1).ToString

Catch Excep As System.Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

Tweak the above code as per your requirement.

Email: pankajmsm@yahoo.com
 
Hey, thanks a lot! i've made some excellent progress with this, and you've helped quite a bit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top