![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
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 Classthen 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 Subso, 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 |
|
|
|
|
|
#2 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
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 |
|
|
|
|
|
#4 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
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? |
|
|
|
|
|
#5 | |
|
Hobbyist Programmer
|
Quote:
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. |
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
|
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|