Lets say we have frmOne and frmTwo. frmOne loads up and when in the main menu the user clicks something frmTwo opens. frmTwo has a bunch of check boxes, ok and cancel buttons. User checks/unchecks the check boxes and clicks ok. frmOne now needs to know what check boxes were checked on frmTwo.

The huge problem that I have is that when frmOne tries to see if the check boxes are checked or not they always return a value that was set in the properties window. If it was set as checked, it will return as checked no matter if the user unchecks it.

Any thoughts would be appreciated. Lemme know if you need code snippets. Solution is being compiled in VB.NET 2008 using 2.0 framework.

Recommended Answers

All 8 Replies

make some shared variable to accommodate state of check box has checked or not. so with shared variable you can access the value of check box from other forms.

I tried making a public variable in the formTwo code but that didn't do anything. Same result.

not a public variable but public shared variable.
this ex of the code (this code running clearly in vb.net 2003, you can try in vb.net 2008 ):

eg your first form named Login

Public Shared Name As String
    Name = txtUserId.text

and this for the call in other forms :

lblNameUser.Text = "Welcome " & Login.Name

you can modified this code to accomodate check box state.

OK.Hope this helps..

commented: i did not know about this variable before +1

Making a new public shared variable for each check box worked perfect, however I'm wondering if there's a way without making all those variables (there are 16 check boxes). Why wouldn't it work directly like this frmTwo.chkBox.Checked called from frmOne.


frmTwo.chkBox.Checked called from frmOne

you cannot call directly cause its private. you cannot access the controls in frmTwo from frmOne, it cause all of controls is private. because of the private state i suggest to use shared variable.

The controls are Friend not private and even when i set the property of the check box to public, it does not work.

hi, i am not so sure i understand where the problem is coming in. i just quickly created an application which created 2 forms... form1 and form2. on form1 i created a checkbox and a button "Go to Form2", which makes form2 visible. From form 2, i created label1 and button1. when button1 is pressed it does an if statement...

If Form1.CheckBox1.Checked = True Then
Label1.Text = "1"
Label1.Text = "0"

End If

it seems to display 100% fine based upon the check state of the checkbox...

where are you having trouble?

Maybe it's the threading I dont know. But here's the Code.

Private UpdateThread As New ThreadControl(AddressOf UpdateControl)

Private Sub UpdateMenu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
   If UpdateForm.ShowDialog() = Windows.Forms.DialogResult.OK Then
   End If
End Sub

Private Sub UpdateControl()
   Dim intNumQueries As Integer = 0
   If UpdateForm.chkHead.Checked Then intNumQueries += 1
End Sub

there are a total of 16 checkboxes on the second form and no matter what intNumQueries always returns 0. When the user clicks the ok button on the second form this is called:

Me.DialogResult = System.Windows.Forms.DialogResult.OK

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.