Question how do i get value of combo box from one user control to another

solutionsdxb

Member
Joined
Mar 18, 2009
Messages
8
Programming Experience
1-3
Hi,

i am using vb.net 2005 to developed desktop application ,

I am having two windows form user control , the first control name con.vb containing the design and code for connecting to database and getting a list of my project values in combo box.

Now the second user control report.vb which i am using to generate some reports , since the code behind is using connection to connect to various project database , so i want to get the value of

First user control into another how i can get the i have tried the below but its giving me error in run time but no error in design or code behind -

MR.MainForm.Connection1.project_combobox.SelectedValue.ToString

Error i am getting is :

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="MDR"
 
A NullReferenceException can occur if there is no item selected in your ComboBox.
To avoid this do something like:
VB.NET:
    If Not MR.MainForm.Connection1.project_combobox.SelectedValue is Nothing Then
        MR.MainForm.Connection1.project_combobox.SelectedValue.ToString
 
but there is already selected itemin the combobox ,is it because of i am calling or using the combobox in the main form , could you pls. check my syntax is correct and how i am using the combobox in user control as this user control is inside the other user control.

with regards
 
What you have to do is to discover which object instance is Nothing. When the error occurs move the mouse-pointer over each object reference in the offending line and wait for the tool-tip to appear. It will either give the value of the instance, or tell you it is Nothing.

I usually find that knowing which is the null instance makes me home in on the cause of the problem.:D
 
Maybe your reffering to values that don't exist. Because after the con.vb form is closed, the values you have put in the combobox are lost.
 
Back
Top