Click here to Skip to main content
15,904,817 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Only 1 column is displaying in my listbox

I want to display FistName and LastName from my database but only FistName is showing.

What I have tried:

VB
'Populate the ListBox with personnelName from personnel '
      Try
          connection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Nikko Jaze Fabellon\Documents\ASRASIM.accdb")
          connection.Open()
          ds = New DataSet
          tables = ds.Tables
          dataAdapter = New OleDbDataAdapter("SELECT [FirstName],[LastName] from [Personnel] where [Status] = 'Activated' ", connection)
          dataAdapter.Fill(ds, "Personnel")
          Dim view1 As New DataView(tables(0))
          With personnelList
              .DataSource = ds.Tables("Personnel")
              .DisplayMember = "FistName"
              .ValueMember = "ID"
              .SelectedIndex = 0
          End With

          connection.Close()

      Catch ex As Exception
          MessageBox.Show(ex.Message)
      End Try
Posted
Updated 14-Feb-18 7:35am

Try:
VB.NET
dataAdapter = New OleDbDataAdapter("SELECT [FirstName] + ' ' + [LastName] AS FullName from [Personnel] where [Status] = 'Activated' ", connection)
dataAdapter.Fill(ds, "Personnel")
Dim view1 As New DataView(tables(0))
With personnelList
    .DataSource = ds.Tables("Personnel")
    .DisplayMember = "FullName"
 
Share this answer
 
Here is a CodeProject example: Multi Column List Box in C#[^]
But a DataGridView is probably more suitable for your purposes, it is also a lot more complex sadly, here is an interesting article about it: A Detailed Data Binding Tutorial[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900