I want to pass an integer value to a form in .Net so that it can load the right data. I’m using this so that when I double click on a record in a list, a form opens with the data from that record loaded so it can be edited. What is the best way to do this? Should I create a property and set it before calling the Show() method, or should I overload the constructor or something and send the value in as an initialisation value that way?
Note – this doesn’t need to work with sending more than one value in to the form – only one value will be needed.
It shouldn’t really matter but this is in C++ .Net.
I’d suggest something else.
create a static method (to the form you want to open) – pass the parameter to the static method.
leave it up to the static method to new up the form, load the data and call the Show method.
this way the calling form doesn’t have to mess with the form to much (ctor, setting the value, calling show) – you keep this logic away and encapsulated in the form – which means you can also re-use it without copying the code.