Solved

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

Posted on 2013-01-28
5
335 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
  • 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 85

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now