Results 1 to 2 of 2
2010-07-27, 06:17 #1
- Join Date
- Jul 2008
- Suffolk, United Kingdom
- Thanked 0 Times in 0 Posts
I need a little help...
I have a visual basic 2010 windows application, with a user control in a form, the user control display's data from a database table call sm_tblProduct. One of the columns in the table is CategoryID this column is an interger datatype. I have another table called sm_tblProductCategory with two columns ProductCategoryID and Description
On the user control I want the combo box CategoryIDComboBox to lookup its value from sm_tblProductCategory, I want it to display in the UI the data from the description column (which is text)
I can get the above to work using the code below, however when I click on the save button, nothing happens, basically because I am trying the save the category description (text) into an interger column
If I change the line 'CategoryIDComboBox.DisplayMember = "Description"' to 'CategoryIDComboBox.DisplayMember = "ProductCategoryID"' the update/save will work but the user is stuck with seeing the product category id only which is not very useable when there are more categories then you can remember the id's of.
Private Sub ucProducts_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As DataTable
Dim ta As New Store_ManagerDataSetTableAdapters.sm_tblProductCat egoryTableAdapter
dt = Store_ManagerDataSet.Tables("sm_tblProductCategory ")
CategoryIDComboBox.DisplayMember = "Description" 'CategoryIDComboBox.DisplayMember = "ProductCategoryID"
CategoryIDComboBox.ValueMember = "ProductCategoryID"
CategoryIDComboBox.DataSource = dt
Many thanks in advance for your time and helpRegards
Gerbil (AKA Kevin)
2010-07-27, 15:46 #2
- Join Date
- Feb 2001
- Silicon Valley, USA
- Thanked 93 Times in 89 Posts
I'm not familiar with .Net comboboxes, but can you create a hidden column and populate that with your key value? Here's a Word doc showing how you could implement that in a VBA UserForm. That's ancient technology, but might give you some ideas.