custom field in DataTable for listbox binding

G

Guest

Hi:
I have a dialog in WinForm with 2 list box, source and destination, and 4
buttons, add, add all, remove and remove all. So user can add single/all
items in source list box to destination one. so as remove and remove all
buttons. I binding a DataTable to source and destination list box. Now my
problem is, in my DataTable, there are fields ID, FirstName, LastName. I like
to show full name in the list box.
What should I do?
 
J

Jesús López

The ListBox control cannot show more than one field at a time, so I suggest
you adding a new calculated field to the datatable witih LastName and
FirstName concatenated. Something like this:

SourceTable.Columns.Add("FullName", GetType(String), "LastName + ',
' + FirstName")
Me.ListBox1.DataSource = SourceTable
Me.ListBox1.DisplayMember = "FullName"
Me.ListBox1.ValueMember = "ID"

Regards from Madrid (Spain)

Jesús López
VB MVP
 
W

William \(Bill\) Vaughn

Write your SELECT to do the concatenation:
SELECT FirstName + " " + LastName AS [Name] FROM ...

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
C

Cor Ligthert [MVP]

wesbird,
Write your SELECT to do the concatenation:
SELECT FirstName + " " + LastName AS [Name] FROM ...
Juan and Bill give you the in my opinion two nicest alternatives (it is just
what you prefer).

Probably do you need for the combobox value as well the ID, in the select
from Bill.

Just as very slight addition to Bills string

:)

Cor
 

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