Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 24th, 2005, 2:57 PM   #1
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 241
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
Unhappy Passing Data between open forms?

Hi there, I'm writing a program and recently hit a brick wall.

Here is an overview of my program. It starts out by opening a form, which spawns a 2nd form, and finally, when a button is clicked in form2 it spawns a 3rd form.

I need to get the data from within the combo box on form3 back to the original outermost form, i am not really sure how to do it though, i have tried reading some stuff online but it's been kind of confusing.

here is my outermost form code, it's an excel workbook project

Public Class Sheet1

    Private Sub Sheet1_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

        Dim LeaveForm As New LeaveRequest
        LeaveForm.Show()

 
    End Sub

    Private Sub Sheet1_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown

    End Sub

End Class



then within my LeaveForm which was just spawned, there is a button handler like so:

  Private Sub butView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butView.Click

        Dim PickerForm As New DatePicker
        PickerForm.Show()
       
    End Sub


so, the question is, i need to get something from within a combo box on that PickerForm all the way back out so i can use it in Private Sub Sheet1_Startup

any help is appreciated, thanks much
melbolt is offline   Reply With Quote
Old May 24th, 2005, 3:45 PM   #2
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
What I usually do is set up the form that must return data to have a readonly property that contains what the user selected. Just set it from inside when the user makes his choice. Be sure to set the DialogResult on the buttons to whatever is appropriate. I would use showdialog rather than show, and if it returns OK rather than cancel or otherwise then check the property to get your data.
Dameon is offline   Reply With Quote
Old May 24th, 2005, 4:56 PM   #3
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 241
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
here is my situation

form1 > spawns form2 > spawns form3(data here)

i need to get the data from form3 back to form1, another important thing to note is that all 3 of the forms will remain open, so i cannot create a new instance of it and maintain my data.

I am not really sure what you mean about how to declare/check the property, think you could put a line or two of code in here as an example?

By this methodology, I would have to move the data from form3 to form2 and finally back to form1? I say this because form1 declares form2, form2 declares form3.

thanks again
melbolt is offline   Reply With Quote
Old May 24th, 2005, 6:39 PM   #4
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
I'm curious why a form needs data from a form it didn't create.

Since you want the forms to remain open, perhaps you should use events?
Dameon is offline   Reply With Quote
Old May 24th, 2005, 8:29 PM   #5
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 241
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
Quote:
Originally Posted by Dameon
I'm curious why a form needs data from a form it didn't create.

Since you want the forms to remain open, perhaps you should use events?

well, the reason is because the original form is an excel spreadsheet, you know how in .Net you can make an excel project workspace. where your main startup form is an excel spreadsheet with a code behind and it cannot be changed. therefore, i must have my initial form invoked at the start of the spreadsheet, however, i need further functionality from a 2nd form, which is invoked from a button on the form prior to it.


my program is like so:

i want it to ultimately generate a filled out excel spreadsheet, it will use the information from the 2 forms to populate it. The first form that is spawned by the spreadsheet's code behind will allow users to enter as many dates in it as they want, for example 12/23/2005 4:00PM - 12/24/2006 5:00PM, they can continue to add as many dates as they want on the first form. by clicking a button they can pop up a little dialogue that will allow them to view all of the dates entered in a combo box and they may choose to delete a date or they may choose to generate a report using that date. So i need to pull that date back to my excel spreadsheet(initial form) where i can then run queries to the database using that date and populate my excel spreadsheet using that query based on the date from the 3rd form.

how might i go about passing the data using events? sorry i've never had to do this before so it's still pretty new to me.

i know i could rethink my whole program design and do it a different way but its been kind of a challenge to me, i hate giving up when i can't figure out how to do something, i can't be satisfied changing it until i have an idea how i could have done it.

Last edited by melbolt; May 24th, 2005 at 8:39 PM.
melbolt is offline   Reply With Quote
Old May 24th, 2005, 9:27 PM   #6
melbolt
Hobbyist Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 241
Rep Power: 4 melbolt is on a distinguished road
Send a message via AIM to melbolt Send a message via Yahoo to melbolt
just wanted to say that i found an excellent explanation on how to do this just incase anyone is interested.

the link is here:
http://msdn.microsoft.com/library/de...adingtonet.asp

it explains how you can either make your form globally available or pass it by reference.

cheers
melbolt is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:20 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC