Mulitple combobox columns

Desperately trying to figure this out??  I have ask this question before but atill having problems with it.

HOW DO I MAKE A COMBOBOX WITH MULITIPLE COLUMNS?

I have an access database, usinf visual studio.net.  I have a form with a combobox and lots of text fields,  the combobox is used to search for a particular record.  I need the combobox to hold the firstname lastname and ID columns of the datatable.

I am looking at creating datatable that will have one column with the ID and another with the last name and the firstname as a concatenated string.  I don't know how i go concatenating two datatable cloumns into one.  

Desperately needing help here.

Nerdy Girl

Nerdy_Girl88Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

flavoCommented:
Hey neardy!

Example of mine

    Dim sSQL As String = "Select PreparerID, (LastName &", " & FirstName) as sName FROM tblPreparer order by [sname];"
            con = New OleDbConnection(Globals.conString)
            con.Open()
            'populate prepare combobox
            Dim cmdPreparer = New OleDbCommand(sSQL, con)
            Dim adptPreparer = New OleDbDataAdapter
            Dim dsPreparer = New DataSet
            adptPreparer.SelectCommand = cmdPreparer
            adptPreparer.Fill(dsPreparer, "tblPreparer")
            Me.cboPreparer.DataSource = dsPreparer.Tables("tblPreparer")
            Me.cboPreparer.DisplayMember = "sName"
            Me.cboPreparer.ValueMember = "PreparerID"
            'Cleanup
            dsPreparer.Dispose()
            adptPreparer.Dispose()
            cmdPreparer.Dispose()


The id is not shown, however can be retrived by using

Me.cboPreparer.selectedvalue

The name is generated like this

Select ID, (firstName & " " & LastName) as Name

                ^^^^^^   ^^^^   ^^^^^       ^^^^
               field            join         other field     alias

More help?? Im a cr@p teacher
0
RonaldBiemansCommented:
Another way is to add the column to your table something like

Lets say you have a table (dt) with the following fields

ID,Fname,Lname


        dt.Columns.Add("Names", GetType(System.String), "Fname + ' ' + Lname")

        ComboBox1.ValueMember = "ID"
        ComboBox1.DisplayMember = "Names"
        ComboBox1.DataSource = dt
0
RonaldBiemansCommented:
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

prakash_prkCommented:
Use a class to store your value
--------------------------------
Class details
    Private _id, _firstName, _lastName As String

    Public Sub New(ByVal id As String, ByVal lastname As String, ByVal firstname As String)
        Me._firstName = firstname
        Me._id = id
        Me._lastName = lastname
    End Sub

    Public Property ID() As String
        Get
            Return _id
        End Get
        Set(ByVal Value As String)
            _id = Value
        End Set
    End Property

    Public Property FirstName() As String
        Get
            Return _firstName
        End Get
        Set(ByVal Value As String)
            _firstName = Value
        End Set
    End Property

    Public Property LastName() As String
        Get
            Return _lastName
        End Get
        Set(ByVal Value As String)
            _lastName = Value
        End Set
    End Property

    Public Overrides Function toString() As String
        Return ID 'the property you want to display in combo box
    End Function
End Class
----------------------------------
use this code to add your object to combo box
Dim temp As New details("89", "gggg", "jsgdghg")
Me.ComboBox1.Items.Add(temp)
---------------------

The to string method is important your define the string you wnat to display in the combobox

Regards
Prakash
0
RacinRanCommented:
The bottom line is you can't have mutiple columns in the combo box.  So you store the ID in ValueMember property and concatenate whatever else you want into one column and put it in the DisplayMember property.


Racin
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nerdy_Girl88Author Commented:
Thank you all for your help....

Flavo
will your code create a datatable  with a column called sName. 'Which will be of string type holding the First name and last name.

 RonaldBiemans
That is exactly what i want to do.  

Just to confirm

 dt.Columns.Add("Names", GetType(System.String), "Fname + ' ' + Lname")

Fname and Lname are already columns in the dt table right?
And this will add a new column to that dt called Names.

Thanks
0
Nerdy_Girl88Author Commented:
RonaldBiemans

All the controls are bound to the same dataset,  I have a search combobox that uses the same datatable in the dataset,  If I use a different dataset to  fill the combobox how will my dataset know which record to display to the form.

Does theis make sense.
0
Nerdy_Girl88Author Commented:
Thnaks guys that works, however now my master detail form doesn't work.  It will only work for the master part.

I think it was because of the way i hace designed by master detail form.

Thanks you have help me with this problem I will post an new thread for the master detail problem.

Cheers
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.