How to pass variables to a new form?
-
Hi everyone. I've got a listBox and a list of elements in it. I've got another windows form, and it will be created after an item in the listBox is double clicked. What I'm asking is; I want to "read" the name of the element from the list box, and then fill the new form according to this information. How can I pass the listBox1's selected Item's text to the new form? can anybody help?
-
Hi everyone. I've got a listBox and a list of elements in it. I've got another windows form, and it will be created after an item in the listBox is double clicked. What I'm asking is; I want to "read" the name of the element from the list box, and then fill the new form according to this information. How can I pass the listBox1's selected Item's text to the new form? can anybody help?
Create a constructor for the new form that takes the information necessary.
I know the language. I've read a book. - _Madmatt
-
Hi everyone. I've got a listBox and a list of elements in it. I've got another windows form, and it will be created after an item in the listBox is double clicked. What I'm asking is; I want to "read" the name of the element from the list box, and then fill the new form according to this information. How can I pass the listBox1's selected Item's text to the new form? can anybody help?
You can just simply write a custom property method for that.
Thanks Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
-
Create a constructor for the new form that takes the information necessary.
I know the language. I've read a book. - _Madmatt
Oh I've not created a constructor about 3 years, I don't remember how to but I'll try, I'll try the articles
-
You can just simply write a custom property method for that.
Thanks Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
you mean a public class that can be reached from the new form? is this it?
-
Oh I've not created a constructor about 3 years, I don't remember how to but I'll try, I'll try the articles
You need to research articles to create a class constructor?!? :omg: Go read some books, take a class, whatever it takes but stop trying to write applications until you do.
I know the language. I've read a book. - _Madmatt
-
you mean a public class that can be reached from the new form? is this it?
Yes, but it depends on how you are going to use the class... you can also use a constructor.
Thanks Md. Marufuzzaman
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you. I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
-
You need to research articles to create a class constructor?!? :omg: Go read some books, take a class, whatever it takes but stop trying to write applications until you do.
I know the language. I've read a book. - _Madmatt
ahhaah just never needed to create one until now =) (just graduated) take it easy, thanks for help and advice :D
-
you mean a public class that can be reached from the new form? is this it?
That would be awful IMHO if all you need is to send selected item. You should used a parameterized constructor. Or have a public event handler so that you can handle the double click event in the Form where you need to get the selected value. Constructor would be the simplest way though.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
-
ahhaah just never needed to create one until now =) (just graduated) take it easy, thanks for help and advice :D
Just graduated? And this wasn't covered? Where did you graduate from?
I know the language. I've read a book. - _Madmatt
-
ahhaah just never needed to create one until now =) (just graduated) take it easy, thanks for help and advice :D
-
Hi everyone. I've got a listBox and a list of elements in it. I've got another windows form, and it will be created after an item in the listBox is double clicked. What I'm asking is; I want to "read" the name of the element from the list box, and then fill the new form according to this information. How can I pass the listBox1's selected Item's text to the new form? can anybody help?
class Form2 {
private string m_Data;internal Form2(string data) { m\_Data = data; } private void Form2\_Load(...) { Use m\_Data here........ }
}
class Form1 {
private void ListBox1_DoubleClick(...) {
Form2 f2 = new Form2(ListBox1.SelectedText);
f2.Show();
}
} -
class Form2 {
private string m_Data;internal Form2(string data) { m\_Data = data; } private void Form2\_Load(...) { Use m\_Data here........ }
}
class Form1 {
private void ListBox1_DoubleClick(...) {
Form2 f2 = new Form2(ListBox1.SelectedText);
f2.Show();
}
}"Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime" Same goes for code.
I know the language. I've read a book. - _Madmatt
-
Hi everyone. I've got a listBox and a list of elements in it. I've got another windows form, and it will be created after an item in the listBox is double clicked. What I'm asking is; I want to "read" the name of the element from the list box, and then fill the new form according to this information. How can I pass the listBox1's selected Item's text to the new form? can anybody help?
SelectedObject = GetSelectedObjectFromListBox(); MyPopUpForm form = new MyPopUpForm(); form.SelectedObject = SelectedObject; form.Show();
orSelectedObject = GetSelectedObjectFromListBox(); MyPopUpForm form = new MyPopUpForm(SelectedObject ); form.Show();
depending on your preference. In the 1st case you need a public property in your popup form, called SelectedObject. In the setter, you need to do what you need to do. In the 2nd case you need a constructor that takes a SelectedObject as a parameter. It is usually inadvisable to use this constructor to populate your form - store it then populate when the form is shown.___________________________________________ .\\axxx (That's an 'M')
-
"Give a man a fish; you have fed him for today. Teach a man to fish; and you have fed him for a lifetime" Same goes for code.
I know the language. I've read a book. - _Madmatt
-
No, you missed the point. We don't give them the code, we teach them to code.
I know the language. I've read a book. - _Madmatt