Solved

Obtaining an integer from a selected combobox item for delivery to second form

Posted on 2013-01-28
5
340 Views
Last Modified: 2013-01-28
Hello:

See the below:
--------------------------------------------
Public Class Form 1

  Dim combolabel As Integer

Private Sub TypeComboBox_SelectedIndexChanged(ByVal ....) Handles TypeCombobox.Selected Index Changed

If TypeCombobox.SelectedItem= "NonProv" Then
form2.combolabel = 360
---------------------------------------------

I'm trying to apply a integer (numerical value) to a selected combobox item, and then have that value passed to a second form in the project.  

However, I am having difficulty generating the integer value 360, which represents "NonProv".  This integer will be used in an equation on form2.  Any ideas on what's wrong with my code?  I've looked many places, but haven't found a good solution.

Robert
0
Comment
Question by:RobertGeoff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 38828957
Is your ComboBox Databound?
0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 38828990
In Your Form2
 
 Public Sub New(ByVal SelInt As Integer)
        InitializeComponent()
        Me.combolabel.text = SelInt
    End Sub

Open in new window

In Your Form1
 Private WithEvents ObjForm As Form

Open in new window

In the SelectedIndexEvent
Private Sub TypeComboBox_SelectedIndexChanged(ByVal ....) Handles TypeCombobox.Selected Index Changed
dim Int as integer

 If TypeCombobox.SelectedItem = "NonProv" Then
int=360
        If objForm is nothing then objForm = New Form2(int)
  End If
..
..
..
    End Sub

Open in new window

If your ComboBox is databound see also
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_28011632.html
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 38829026
You have:

    form2.combolabel = 360

How was "form2" displayed?  You haven't shown how "form2" was declared.  If it wasn't, then the line above is accessing the "default instance" of Form2.

If, however, you displayed Form2 using the "new" keyword, then you are not accessing the same instance and that is the root of your problem:

    Dim f2 As New Form2
    f2.Show()

If this is the case, then you either need to switch all access to the default instance, or keep the reference to "f2" and use that to set the 360 value.
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 38829057
I also forgot the Form2.Show after the declaration

Nice to "meet" you again Idle_Mind
0
 

Author Closing Comment

by:RobertGeoff
ID: 38829407
My button click event to connect form 2 and form 1 is not indicated as "reference to a non-shared member requires an object reference".  This will need to be addressed.
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question