Filling a listbox frustration

G

Guest

I’m trying to populate a listbox with data that comes from my SQL server.
I’ve created the connection, filled the dataset and loaded the data adapter.
Apparently, I’m missing something because after this runs, what is populated
in the listbox is: “System.Data.DataRowView†for each record in my data
adapter.

When I click on one of the rows (which really doesn’t make sense) as I test
the rest of my routine, I’m able to trick it into showing me other data from
that row.

Below is the piece of code that I'm trying to use to load my listbox.

'Fill the data adapter
daEmployeeTree.Fill(dsEmployeeTree, "SuperInfo")

' create data view
Dim dv As DataView = dsEmployeeTree.Tables("SuperInfo").DefaultView
lbxEmployee.DataSource = dv
lbxEmployee.DisplayMember = "SuperInfo"
lbxEmployee.DisplayMember = dv.ToString

Can someone help me fill my listbox with meaningful data? As you can tell,
I’m new to this so any and all help is greatly appreciated.

Thanks,
 
G

Guest

You need to bind the data to the listbox
after you assign the fields to it.

lbxEmployee.DataBind()
 
G

Guest

Basic syntax to populating a listbox

With ListBox1
.DataSource = "Data Source"
.DataMember = "Table_Name"
.DataTextField = "table_Column_name1" ' This is the text that
will show in listbox
.DataValueField = "table_Column_name2" 'This is the value behind
the text if left out will take on the value of the DataTextField"
.DataBind()
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top