[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 342
  • Last Modified:

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

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
RobertGeoff
Asked:
RobertGeoff
  • 3
1 Solution
 
John (Yiannis) ToutountzoglouCommented:
Is your ComboBox Databound?
0
 
John (Yiannis) ToutountzoglouCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
John (Yiannis) ToutountzoglouCommented:
I also forgot the Form2.Show after the declaration

Nice to "meet" you again Idle_Mind
0
 
RobertGeoffAuthor Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now