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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate Listbox from Dataview 1

Status
Not open for further replies.

LFCfan

Programmer
Nov 29, 2002
3,015
GB
Hi

I have a listbox on a windows form that i want to populate with items from a dataview.
i have the following:

Dim dsDatabases As DataSet
Dim dtDatabases As DataTable
Dim dvDatabases As DataView

dsDatabases = GetDatabases()
dtDatabases = dsDatabases.Tables("Databases")
dvDatabases = dtDatabases.DefaultView
dvDatabases.RowFilter = "DBName LIKE 'CCRAccount_[%]' AND DBName LIKE '[%]dk'"

Me.ListBox1.DataSource = dvDatabases
Me.ListBox1.DisplayMember = "DBName"
Me.ListBox1.ValueMember = "DBName"
Me.ListBox1.Refresh()


...but unfortunately the listbox is empty!
i'm totally baffled, and i've hunted high and low to find an example or something in the online help and various forums, but nothing's helped. (i'm quite new at all this, in case this wasn't glaringly obvious!)

i'm probably missing something very basic here - any suggestions would be very much appreciated.

TIA
LFCfan

 
I have used datarow and iterated through the rows and populated the listbox. I tried this method below and works fine for me. This might not be the most efficient method, but it works

Private Sub loadListbox(ByVal selectString As String)

oConn.Open()
oQuery = "Select * from JOBLIST"
oCommand = New OleDbCommand(oQuery, oConn)
oAdapter = New OleDbDataAdapter(oCommand)
oJobDataset = New DataSet()
oAdapter.Fill(oJobDataset)

JobListBox.Items.Clear()

Dim oDataRow As DataRow
oTable = oJobDataset.Tables(0)
Dim objResults() As DataRow
objResults = oTable.Select("JOBLIST_NAME LIKE '" & selectString & "%'", "")
For Each oDataRow In objResults
JobListBox.Items.Add(oDataRow("JOBLIST_NAME"))
Next

End Sub
 
Thanks kbalaji
That's done the trick!
I couldn't get the .DataSource way to work, and i've been trying to for most of the day!!

Thanks again

LFCfan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top