How to bind two columns to DisplayMemeber in a List box

  • Thread starter Thread starter suresh munagala
  • Start date Start date
S

suresh munagala

Hi,

I want to display two columns of information in a listbox.
For Example I have two columns in the database as
FirstName and LastName. In the ListBox I want to display
as FirstName+LastNamea as a single column. I know how t
odo this, if i have to display a single column.

myListBox.DataSource = dsNames
myListBox.DisplayMember = "FirstName"
//in the above line i would like to specify both the first
nama and the last name.like"FirstName - LastName"

Is it possilbe? Or i have to do on my own?

Thank you
Suresh
 
suresh munagala said:
Hi,

I want to display two columns of information in a listbox.
For Example I have two columns in the database as
FirstName and LastName. In the ListBox I want to display
as FirstName+LastNamea as a single column. I know how t
odo this, if i have to display a single column.

myListBox.DataSource = dsNames
myListBox.DisplayMember = "FirstName"
//in the above line i would like to specify both the first
nama and the last name.like"FirstName - LastName"

Is it possilbe? Or i have to do on my own?

Thank you
Suresh

The most straight-forward way would be to create a dynamic column when
SELECTing from your database. Instead of "SELECT FirstName, LastName
<whatever>", use "SELECT FirstName + ' ' + LastName as FullName <whatever>".
Granted, the syntax may need tweaked for your particular database, but the
idea is the same. Having done so, you can bind your listbox's DisplayMember
to "FullName".

Good luck,
Ryan LaNeve
 
Back
Top