comboBox.DisplayMember Complex string?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I wanted to set a DisplayMember of a comboBox with the text of 2 Columns of my Datatable, for example

comboBox.DisplayMember = "id" + " " + "name
comboBox.ValueMember= "id

I allready try "id" + " " + "name", "id, name" but none work, how can I do this

Thanks in advanc

Pedro
 
Pedro said:
I wanted to set a DisplayMember of a comboBox with the text of 2
Columns of my Datatable, for example:

comboBox.DisplayMember = "id" + " " + "name"
comboBox.ValueMember= "id"

I allready try "id" + " " + "name", "id, name" but none work, how can I do this?

I believe the easiest way is probably to add a computed column to your
data-table which does the concatenation, and then make the
DisplayMember of the combobox the name of the computed column.
 
Hi Pedro:

If you read the first few paragraphs here
http://www.knowdotnet.com/articles/dataviews1.html I walk you through this.
John is right (as always) that an expression column will allow you to do
this , and you can bind to the expression column while still keeping your
valuemember and in addition, you can have your changes automatically
reflected in teh combobox. Some people will recommend pulling it over in
the SQL Statement which will work, but it won't update itself if you change
the fields in the datatable.... much easier, cleaner and more efficient to
must use the expression column.
 
Back
Top