• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

CheckState with checkbox how do i save the forms state(im reading/checking this from another form)

i have:
If (EMail_Options.Welcome_Msg.CheckState.Checked) Then

i found when i goto the form its on i check the box then close the form it disapers


how do i svae this state??

thx
Johnny
aka Pern
0
Johnny
Asked:
Johnny
  • 4
  • 3
  • 2
2 Solutions
 
ihenryCommented:
The most easier is using session variable and set AutoPostback of the CheckState checkbox to true.

      Sub Check_Clicked(sender As Object, e As EventArgs)
         ' Store the checked state to session variable
         Session("CheckState") = EMail_Options.Welcome_Msg.CheckState.Checked
      End Sub

And in another form, get the state from session like the following

      If Not IsNothing( Session("CheckState") ) Then
         Dim isChecked = CType( Session("CheckState"), Boolean )
      End If
0
 
ihenryCommented:
Forgot to mention,
The Check_Clicked event is triggered when the checkbox is clicked.
0
 
ihenryCommented:

Another things..my suggestion won't work if you're working on Windows Form... forgot to ask, my mistake..
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
ihenryCommented:

Ok, if you're working on Windows Form

Declare one public shared variable in the form that contains the checkbox,

    Public Shared IsChecked As Boolean = False

And handle checked_changed event of the checkbox,

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        IsChecked = CheckBox1.Checked
    End Sub

And in another form, you can easily retrieve value from the variable

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim b As Boolean = Form1.IsChecked
    End Sub
0
 
JohnnyAuthor Commented:
its on a windows form


its not working right. when i come back after ckloseing the form(its on an options tab [form1) its not checked..

how do i keep it the vlast value it is...

and then read it from your example [form2]

thx
0
 
flavoCommented:
maybe something like

Main Form

Dim frm as new myOtherForm
frm.showDialog

If frm.dialogresult = dialogresult.oK then
  me.myCheckbox.checkedstate = true 'cant remeber the acutall property sorry
else
  me.myCheckbox.checkedstate = false 'same goes here
end if


Other form

Say you have a button Close, then on the clic kevent use something like


If me.checkBox = true then
  Me.dialogresult = dialogresult.oK
else
  Me.dialogresult = dialogresult.cancel
end if
Me.close

Not sure if this will work, but seems ok to me..

NOTE: i dont have VS on me at the moment, so please mind the air code...


Dave

0
 
JohnnyAuthor Commented:
i figured it out...i saved the state to the registry and read it each time the form is opened this way i can check it in other areas as well...

im splitting the points as you both tryed to answer and i dont feel like asking for my points back...


heres how i did it for those who wish to know

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21023595.html

thx for the help as always
0
 
flavoCommented:
just thought of something

create a new module

then

private bCheck as boolean

public property chk() as boolean

Get
   reutrn bCheck
end get
set(byVal value as boolean)
    bCheck = value
end set

end property


and use myModule.chk to pass the value around...  This is how i do my Connextion strings after getting it from a encrypted string in the app.config

Anthoer idea, which i think is cleaner than registry..

Dave
0
 
JohnnyAuthor Commented:
my problem is i am checking it from alot of other areas... and doing more then just the one check...

and i found i have to be on that form (the one that assigns the values) to have it work..if i save the values its a one time write and meny read type of thing...saving the values i can read the next time the forms open...

so the registery solution works really well...

thx for still trying...

Johnny
aka Pern
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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