?
Solved

Identify textbox whose text matches combobox in vb.net

Posted on 2014-11-19
3
Medium Priority
?
225 Views
Last Modified: 2014-11-20
Hi all.

I'm working on a vb.net form in Visual Studio 2012 that has 5 textboxes (txtbox1, txtbox2, etc.) and a combobox (mycombobox).

The combobox list shows the 5 values in each of the textboxes described above. After the end user selects an item from the combobox I want to display in a message box which textbox has the exact value. So the message box would display "txtbox1" if the text inside of it matched what was selected in the combobox.

Any ideas?

Thank you in advance.
0
Comment
Question by:printmedia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 40453741
How are you populating the ComboBox? If you post that code it'll help in determining the correct textbox.
0
 

Author Comment

by:printmedia
ID: 40453752
Private Sub cmbSetMin_Enter(sender As System.Object, e As System.EventArgs) Handles cmbSetMin.Enter

        cmbSetMin.Items.Clear()

        If Not (String.IsNullOrWhiteSpace(txtQty2.Text)) Then cmbSetMin.Items.Add(txtQty2.Text)
        If Not (String.IsNullOrWhiteSpace(txtQty3.Text)) Then cmbSetMin.Items.Add(txtQty3.Text)
        If Not (String.IsNullOrWhiteSpace(txtQty5.Text)) Then cmbSetMin.Items.Add(txtQty5.Text)
        If Not (String.IsNullOrWhiteSpace(txtQty7.Text)) Then cmbSetMin.Items.Add(txtQty7.Text)
        If Not (String.IsNullOrWhiteSpace(txtQty9.Text)) Then cmbSetMin.Items.Add(txtQty9.Text)

        cmbSetMin.SelectedIndex = -1

    End Sub

Open in new window

0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 40454205
		For Each ctl As Control In Me.Controls
			If TypeOf ctl Is TextBox AndAlso ctl.Text = ComboBox1.Text Then
				MessageBox.Show(ctl.Name)
			End If
		Next

Open in new window


This will loop through all the TextBox controls on the form. If you want to make sure that you check only for specific controls, add something in their Tag property (X in the following example) and go like this:

 
		For Each ctl As Control In Me.Controls
			If CStr(ctl.Tag)="X" AndAlso ctl.Text = ComboBox1.Text Then
				MessageBox.Show(ctl.Name)
			End If
		Next

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question