superlative
asked on
VB.NET 2005 Combobox, Multiple Values per line
I have Visual Studio 2005 and am coding in vb.net.
On a form I have a combobox which is populated with values from a database.
In this particular example it is bound to the results from a dataset of room numbers. In the combobox once populated the values look like ,
501
502
503
504
505
etc etc.
Now is it possible to have in the combo box multiple information on each line. e.g. I want to have the room number and the type of room. eg.
501, Standard Double
502, Standard Twin
503, Suite
And then when ever one of these is selected from the drop down, I only want the LEFT hand side of the COMMA to display as the selected value, eg if i was to click on 502 from the dropdown, only '502' would display as the selectedtext value.
Any help hugely apreciated
On a form I have a combobox which is populated with values from a database.
In this particular example it is bound to the results from a dataset of room numbers. In the combobox once populated the values look like ,
501
502
503
504
505
etc etc.
Now is it possible to have in the combo box multiple information on each line. e.g. I want to have the room number and the type of room. eg.
501, Standard Double
502, Standard Twin
503, Suite
And then when ever one of these is selected from the drop down, I only want the LEFT hand side of the COMMA to display as the selected value, eg if i was to click on 502 from the dropdown, only '502' would display as the selectedtext value.
Any help hugely apreciated
Do you need to se the booth values or can you see just the description ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ComboBox by default doesnt support this, but here are links how to implement this
http://www.codeproject.com/vb/net/multicolumncombo.asp
http://www.vbaccelerator.com/home/NET/Code/Controls/ListBox_and_ComboBox/Icon_ComboBox/article.asp
Goran
http://www.codeproject.com/vb/net/multicolumncombo.asp
http://www.vbaccelerator.com/home/NET/Code/Controls/ListBox_and_ComboBox/Icon_ComboBox/article.asp
Goran
If you want to show booth info you can use http://www.codeproject.com/cs/combobox/multicolumncombo.asp
ASKER
Almost what I am after. The multicolumn will have to do. Kinda what i'm after.
I have the following code which works;
myCommand.Connection = conn
myCommand.CommandText = "SELECT * FROM config_roomtype"
Try
conn.Open()
myCommand.ExecuteNonQuery( )
myAdapter.SelectCommand = myCommand
myAdapter.Fill(dt)
cboRoomType.DataSource = dt
cboRoomType.DisplayMember = "type_shortcode"
cboRoomType.ValueMember = "type_name"
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
conn.Dispose()
End Try
However, what I mean is rather than have multicolumns, I wanted the selected value to show in the combo text field the short code, but if you click the down arrow it shows the long name. So I assume there msut be some kind of way to change the combobox.text value when a long version name is selected from the combo's drop down, to then change the text value to be the shortcode version of that long name selected type.
I don't know if that is clear enough? Sorry guys.
I have the following code which works;
myCommand.Connection = conn
myCommand.CommandText = "SELECT * FROM config_roomtype"
Try
conn.Open()
myCommand.ExecuteNonQuery(
myAdapter.SelectCommand = myCommand
myAdapter.Fill(dt)
cboRoomType.DataSource = dt
cboRoomType.DisplayMember = "type_shortcode"
cboRoomType.ValueMember = "type_name"
Catch myerror As MySqlException
MessageBox.Show("Error Connecting to Database: " & myerror.Message)
Finally
conn.Dispose()
End Try
However, what I mean is rather than have multicolumns, I wanted the selected value to show in the combo text field the short code, but if you click the down arrow it shows the long name. So I assume there msut be some kind of way to change the combobox.text value when a long version name is selected from the combo's drop down, to then change the text value to be the shortcode version of that long name selected type.
I don't know if that is clear enough? Sorry guys.