Solved

Identify textbox whose text matches combobox in vb.net

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now