andycharger Posted May 4, 2004 Posted May 4, 2004 I have a form which we shall call frm1. I have a combobox that populates correctly from my database. When my users click on an item in the list and press select, I want to open another form, frm2, pass it the selectedValue from my combobox on frm1 and do another search. How do I get the value to the next form (frm2)? I know the Selected Value is correct because i built a messagebox to tel lme the value when the button is pressed. Any ideas? Andy Quote
mocella Posted May 4, 2004 Posted May 4, 2004 Create an overload constructor in Form2 that accepts that selected-value. Quote
andycharger Posted May 4, 2004 Author Posted May 4, 2004 How? Can you provide some example code to create an overload constructor? Basically here is my code: frm1: Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim PassVal As New Frm2() intPassedVal = ComboBox1.SelectedValue PassVal.Show() end sub then frm2 has this line in initializecomponent TextBox2.Text = Frm1.intPassedVal this just leaves me with a blank textbox. Quote
Arch4ngel Posted May 4, 2004 Posted May 4, 2004 On my side... I use the Session object which is rather more secure and faster. You might try to work with overload but the Session object worked fine for me. Session.Add(name,value); Session[name] = value; // Doesn't work if it's not existent Quote "If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown "Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me "A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend. C# TO VB TRANSLATOR
Administrators PlausiblyDamp Posted May 4, 2004 Administrators Posted May 4, 2004 Arch4ngel - he did mention a form and post this in the windows forms forum - perhaps session isn't going to be the best solution here. This thread in the tutor's corner may be of some help. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Ice725 Posted May 4, 2004 Posted May 4, 2004 My problem is the opposite of andycharger... Say frm1 generates 5 numbers. To add a new number, frm2.showDialog() is fired. He can pick from some more numbers on this form, frm2. When he finds the one he wants, he clicks OK button. So with this example, how could i send back the number the user picks from frm2 back to the main form, frm1? Quote
mocella Posted May 4, 2004 Posted May 4, 2004 Create some public properties in your second form and access these when you return to the first form. Quote
PROKA Posted May 6, 2004 Posted May 6, 2004 as I said in another post, to pass values between 2 or more forms, I create a module and I declare those public Variables, classes etc in that Module . I can access them from any other form in my project . ;) Quote Development & Research Department @ Elven Soft
*Experts* DiverDan Posted May 6, 2004 *Experts* Posted May 6, 2004 You can also access a public variable without creating a module In Form1: Public Shared publicInfo(20) As String can be accessed by any form as Form1.publicInfo(0), Form1.publicInfo(1), etc. I personally prefer arrays as they can pass almost anything between forms. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.