Value to transfer to .Net

I want to pass an integer value to a form in .Net so that it can load the data I want. I use this so that when I double click on a record in the list, a form opens with the data from the loaded record so that it can be edited. What's the best way to do this? Do I have to create a property and set it before calling the Show () method, or do I need to overload the constructor or something and send the value as an initialization value this way?

Note. This doesn't have to work with submitting more than one value to the form - only one value is required.

It doesn't really matter, but it's in C ++. Net.

0


source to share


3 answers


I suggest something else.

create a static method (to the form you want to open) - pass a parameter to a static method.



leave it up to the static method to update the form, load the data, and call the Show method.

This way the calling form doesn't have to mess with the form much (ctor, setting the value that calls the show) - you keep that logic and encapsulate in the form, which means you can also reuse it without copying your code.

+4


source


Make it mandatory in the constructor. It would be pointless to have one of these forms anyway if you have nothing to edit.



0


source


Add a new constructor that takes an argument and calls the default constructor. By keeping the default constructor, you can still use the Visual Studio Forms Designer, and all your new designer needs is to store the value.

Or you can just add a public property that stores the value. Then you create an object of the forms class, set the property and display the form.

0


source







All Articles