Solved

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

Posted on 2013-01-28
5
334 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
Comment Utility
Is your ComboBox Databound?
0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
I also forgot the Form2.Show after the declaration

Nice to "meet" you again Idle_Mind
0
 

Author Closing Comment

by:RobertGeoff
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

11 Experts available now in Live!

Get 1:1 Help Now