Solved

Identify textbox whose text matches combobox in vb.net

Posted on 2014-11-19
3
220 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
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 500 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

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