How can I read SelectedIndex Property of a combobox from another Form?

NeuralJack

Centurion
Joined
Jul 28, 2005
Messages
138
I'm working with 2 active forms. Form1 has a combo box, Form2 has a button with a context menu on it.
Anytime I click the context menu on form2 and try to obtain the .SelectedIndex property of the combobox on Form1 it always just returns "-1" even though it is obviously isnt "-1". Because I can see that their is a valid selection in the combo box.

Any Ideas? I have tried making the context menu a public entity by declaring it in a module, but that didnt work either. The button is also a public entity btw, and declared in a module.

I'm sure it's some sort of scope problem?
 
Thanks again PD, you had it exactly right. And the link you gave helped solve the issue. I had solved this before in another program long ago, but working with too many Module declared things made me forget about it.

I'm thinking of stopping the Module use altogether now. Is there any benefit/use of Modules in .Net ? Why do they still have them?



PlausiblyDamp said:
It would help if you posted the relevant code you are using to access the other form - it sounds like you could be creating a new instance of the form rather than referencing the existing instance.

http://www.xtremedotnettalk.com/showthread.php?t=83092 is probably worth a read as it covers the general ideas.
 
There are two reasons that you could want to use a module. One is for backwards compatability with VB6, and the other is for a lack of a static class. A module is essentially the same as a static class. You can, however, create a class that is sealed with a private constructor to create the same exact effect as a static class. The big difference between the two is that there is an implicit project-wide import of a module (which is less object-oriented and more disorganized, which is why many prefer to not program with modules).
 
Back
Top