Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Other Columns From a Combo Box's Data Source 1

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
This has probably been answered many times, but I can't find the solution. I have a combo box with an employee table as a data source. I would like to get the department code of the selected employee, both of which are in the same record of the table. I have managed to work around this by looping through the table and finding the selected employee and getting the department code. Seems like there should be an easier method. Probably something simple I'm missing.

Auguy
Sylvania/Toledo Ohio
 
Please show your code. You should be able to display the Employee with the Dept Code as the ItemValue.

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
Hi Auguy,

I have a similar feature on a form, the combo box uses a Data Bound Item, with the Data source set to an existing table adapter against the User table. The Display Member is the Username and the Value member is the Primary Key of the table being queried.
I have the left the Selected Value option as (none) by default.

eg
Jon - 01
Steve - 02

Selecting Jon returns value 01.

Hope that helps.

Cheers,

Jon
 

You can use a CurrencyManager to do this. First, Dim the CurrencyManager object as Global to the form.

Dim cm As CurrencyManager
Dim drvSelectedFromCombo As DataRowView

Next, where you assign the DataTable to the ComboBox, set the Currency Manager:

ComboBox1.DusplayMember = "Username"
ComboBox1.ValueMember = "UserID"
ComboBox1.DataSource = DataTable1

[red]cm = ComboBox1.BindingContext(DataTable1)[/red]


Finally, in the ComboBox's SelectedIndexChanged event:

drvSelectedFromCombo = CType(cm.Current, DataRowView)


Now, drvSelectedFromCombo will contain a DataRowView of the row behind the selected item in the ComboBox.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thank you Jebenson, that's exactly what I was looking for. Makes me wonder what else I can use this technique for.

Auguy
Sylvania/Toledo Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top