Lookup Table

tbpowers

Active member
Joined
Dec 12, 2011
Messages
41
Programming Experience
Beginner
I have a lookup table that contains a label that describes the data to be written back to my database.

For example:

Label = Manufacturing Repair Issue (This is what the user see's in my front-end windows app)
Data = Mfg_Repair (What I want to save to the database when the user choses the label)

Any idea how to accomplish this?
 
You can populate a DataTable with the two columns and then bind that to a ComboBox. Specify "Label" as the DisplayMember and "Data" as the ValueMember. When the user selects a Label value from the visible list, you can get the corresponding Data value from the SelectedValue of the control.
 
I can not get this to work. It will only write back my label value. Is it because I am using a stored procedure as the data source for my table column? Any ideas?
PART_CATEGORYComboBox

Data Source = STPPARTCATEGORYBindingSource
Display Member = LABEL
Value Member = VALUE
Selected Value = STPPARTCATEGORYBindingSource - VALUE
 
Also, it will not let me chose other selections in my drop down if I set the Selected Value as the same as my Value Member (VALUE/VALUE).
 
No code. I am using the Combobox tasks. I am trying to display information from a lookup table and send the selected value into another table's field. I came across some code I am now trying to get to work. Here is that code:

Private Sub STP_PART_CATEGORYComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles STP_PART_CATEGORYComboBox.SelectedIndexChanged
Dim b As New System.Windows.Forms.BindingSource("SelectedValue", Me.REPAIRBindingSource, "dbo.REPAIR.PART_CATEGORY", True)
Me.STP_PART_CATEGORYComboBox.DataBindings.Add(b)
End Sub
 
I am pulling my hair out over this. Could it be because their is not a direct relationship between my lookup table and the table I want to save the data to? My lookup table is a stand alone table. It works great, but I can only get it to write back the Display Member.
 
Still no luck with this. It will write the label back to the database, but not the value. Any futher help will be greatly appreciated.
 
Could you not have an array in the code, possibly read from a support text file, that looks up the value to write? So when 'Label = Manufacturing Repair Issue' the lookup searches and returns 'Mfg_Repair' and writes it.
 
I finally figured this out. I was binding the stored procedure to the table column, so I flipped it and bound the table column to the stored procedure. Worked like a charm! Thanks for all the help. It is appreciated.
 
I have one more issue. On a new record my combobox is showing the first item in the list. How do I get it to show empty until the user choses an item?
 
I figured it out. I did not have the "Selected Value" setup correctly. I have learned alot about comboboxes this week. Good stuff to know!
 
To have any combo decode an ID into readable text you should:

Set its dropdownstyle to list
Set its datasource to a decode data table containing ID and nicetext columns
Set its display and value members to strings equal to the column names in the decode datatable
Crucially, if you drag and drop the combo onto a form from the data sources window you MUST remove the databinding from Text and bind SelectedValue to the column of the datatable you want the combo to edit

The last part is crucial. SelectedValue must be bound. See the (databindings) entry of the properties for the combo for more info
 
Back
Top