Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Here is my probelm, I have one project and multiple forms. The main form called frmMain has blank labels on them to display totals, my second form called frmWheels, has radio buttons that contain text that shows the price. And when the user selects a radio button and then click a ADD button the the form to copy the price to the first form blank label. My problem is that I dont know how to get the prices from the second form to the first form
Posted

so you mean something like this

 

frmMain.lblTotalDisplay.Text = frmWheel.wheelPrice , where WheelPrice is a variable storing the value from the selected radio button on the second form?

Posted

i think you need to pass a reference from the first form to the second .. something like this:

 

// first form
FormWheels frmWheels = new FormWheels(this);
frmWheels.Show();

 

declare FormMain and add it as an argument to the constructor of the second form.

 

then you can target anything on frmMain from frmWheels.

 

Make sure anything you want to target is "public" though. otherwise it won't work.

  • *Experts*
Posted

You would have to pass the instance of the first form to the second one to access it from the second form.

Here is how you could do it:

In the second form find the constructor and edit it so it looks like this:

'a variable that you will use in your second from to reference the nistance of the first one
Dim firstform As Form1

Public Sub New(byval form1var As Form1) 'accept an instance of the form
firstform = form1var 'assign the passed in instance to the local variable
MyBase.New()
InitializeComponent()
End Sub

Then you can access the passed in instance using the firstform variable.

Now, when declaring a new instance Form2 declare it like this:

Dim secondform As New Form2(Me)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...