Solved

Identify textbox whose text matches combobox in vb.net

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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