NeuralJack Posted September 24, 2006 Posted September 24, 2006 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? Quote Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
Administrators PlausiblyDamp Posted September 24, 2006 Administrators Posted September 24, 2006 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
NeuralJack Posted September 25, 2006 Author Posted September 25, 2006 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? 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. Quote Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
Leaders snarfblam Posted September 26, 2006 Leaders Posted September 26, 2006 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). Quote [sIGPIC]e[/sIGPIC]
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.