combo box linking to a textbox

G

Guest

hi, this is the code i have to put the text ina combo box thats being show
into a text box

Private Sub cmbteams_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmbteams.SelectedIndexChanged

If cmbteams.SelectedIndex <> -1 Then
Me.TextBox1.Text = Me.cmbteams.SelectedItem
End If

End Sub

then, if i try to call it later from a different form to see what the text
is, all it shwos is "TextBox1", heres how i call it

Private Sub lblaa5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lblaa5.Click
Me.lblaa5.Text = team.TextBox1.Text
End Sub

lblaa5 is a label on one of my forms, its text is what i want to be the same
as the other form(team)'s textbox to be when i click on the label

thanks
 
C

Cor Ligthert [MVP]

iwdu15

Try to set in top of your program or your in your options
Option Strict On it will warn you for the kind of errors you probably get
now.

With Option Strict Off, your program is in a kind of VB6 compatible state.

You will than see that moving the value of the Combobox (not linking) will
be
Textbox1.Text = Combobox1.SelectedItem.ToString

The other problem, you needs what kind of forms you use.
For that is needed that you tell how you show your form, which can be as a
child of your parentform, the owner. As a Mdiform or as a dialog
(showdialog) or a complete seperated form started in a module.

I hope this helps,

Cor
 
G

Guest

I use the .show command to show it, but i have it so its always on top, but i
did the code u showed me and put "option strict on" and it still didnt work,
it still shows "TextBox1"
 
C

Cor Ligthert [MVP]

iwdu15,

Can you show us the code that you used?

As well which you use to create that second form

Cor
 
G

Guest

sure, heres how i declare the second form:

Dim team As New pickateam

pickateam being the form with the textbox on it

heres how i open it:

Dim frm As New pickateam
frm.Show()

and the rest of the code i already showed but il post again


Private Sub cmbteams_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles cmbteams.SelectedIndexChang
If cmbteams.SelectedIndex <> -1 Then
Me.TextBox1.Text = Me.cmbteams.SelectedItem.ToString
End If

End Sub

then to get the text from the textbox:

Private Sub lblaa1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lblaa1.Click
Me.lblaa1.Text = team.TextBox1.Text
End Sub
 
C

Cor Ligthert [MVP]

iwdu15

It is strange that the code you show does not work.

To be sure I tested it again

\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim frm As New Form2
frm.Owner = Me
frm.Show()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal _
sender As System.Object, ByVal e As System.EventArgs) _
Handles ComboBox1.SelectedIndexChanged
TextBox1.Text = ComboBox1.SelectedItem.ToString
End Sub
///
And then form2 as you want
\\\
Private Sub Button1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = DirectCast(Me.Owner, Form1).TextBox1.Text
End Sub
////

I hope this helps,

Cor
 
G

Guest

hi, i figured out the problem, i accidently declared the form as 2 different
names and used one to open it and the other to say what the textbox was...so
thanks anyway
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top