Solved

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

Posted on 2013-01-28
5
339 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

759 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