Link to home
Start Free TrialLog in
Avatar of Mezillinu
MezillinuFlag for Malta

asked on

How do you put more than 1 columns in a combo box in vb.net when filling from a dataset?

I am populating a combobox from a dataset, that I have 3 columns in but cannot seem to find a way to input 3 columns in this combobox.  Could somebody show me how please?

The code below shows just adding the menuitemid column, but i want to add 2 more columns, how can this be done?  the two other columns are displayname and menuitemurl

Thanks, all help is appreciated
Dim myAdapter As New SqlDataAdapter("select [menuitemid],[displayname], [menuitemurl],[isadmin] from tbl_menuitem where isAdmin = " & isAdmin & "order by menuitemid", conn)
        Dim collection As New DataSet
        myAdapter.Fill(collection, "tbl_menuitem")
        cmbParentMenuItemId.Items.Clear()
 
 
        For Each ds As DataRow In collection.Tables(0).Rows
            cmbParentMenuItemId.Items.Add(ds.Item("menuitemid"))
        Next

Open in new window

Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

With the regular combobox you only can show one column. You can only use one column to display and one with the value (hidden).

If you need more you have to use any other custom control like this on http://www.codeproject.com/KB/combobox/mccombobox.aspx

You can also check more in http://www.codeproject.com/KB/combobox/
Avatar of Mezillinu

ASKER

this is in c++, which i have no idea of, do you know somewhere else that i could have a quick look? i think im going to elimiate this option and try do something instead - i thought it was a simple thing to do, from what it looks like its not :s

do listboxes support 2 columns?
I found a solution! Dumb me, did not think of this before! :s
  For Each ds As DataRow In collection.Tables(0).Rows
            Dim menu As String = ds.Item(0).ToString + " - " + ds.Item(1).ToString
            cmbParentMenuItemId.Items.Add(menu)
        Next

Open in new window

Yes, that work but is not real column. If the value in ds.Item(0).ToString have diferent lenghts then the second "column" doesn't fit nice.

What to you have in ds.Item(0).ToString ?
If you look better on codeproject or google it you will find more examples of multi-column comboboxes. Also listbox or listview can have multicolumns but the advantage of listbox, is this case, is that can be bound.
in ds.item(0).tostring I have the ID of the object.  
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial