VB.NET Question

J

John Smith

Say i have Form1 with comboBox1 and Form2 with comboBox2..

When i click on Form1 button, Form2 will appear on top of Form1...

My Code:


Code:
' Form1 button
Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOne.Click
Dim form2 As New Form2
form2.ShowDialog()
End Sub


How to add the items from Form2 's comboBox to Form1 's comboBox...

My Code:
Code:
' Form2 button
Private Sub btnTwo_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnTwo.Click
Dim form1 As New Form1
form1.comboBox1.Items.Add(Me.comboBox2.Text)
End Sub


These code will not have any effect on comboBox1 in Form1..

Thanks
 
G

Guest

Hi John

When ShowDialog returns, you can get access to its controls inside your
form1 code. This is as long as your controls use the default of Friend access
in your form. Your btnTwo button should have its DialogResult property set to
DialogResult.OK for the code below to work. (And I wrote this without VS, so
if it's wrong, I apologise...)

HTH

Nigel Armstrong

Private Sub btnOne_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOne.Click
Dim form2 As New Form2
If form2.ShowDialog() = DialogResult.OK Then
Me.comboBox1.Items.Add(form2.comboBox2.Text)
End If
End Sub
 

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