Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted

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?

Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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.

Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
  • Leaders
Posted
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).
[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...