Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-10-24
9
Medium Priority
?
254 Views
Last Modified: 2010-04-24
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
Comment
Question by:Johnny
  • 4
  • 3
  • 2
9 Comments
 
LVL 20

Accepted Solution

by:
ihenry earned 750 total points
ID: 12394583
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
 
LVL 20

Expert Comment

by:ihenry
ID: 12394592
Forgot to mention,
The Check_Clicked event is triggered when the checkbox is clicked.
0
 
LVL 20

Expert Comment

by:ihenry
ID: 12394609

Another things..my suggestion won't work if you're working on Windows Form... forgot to ask, my mistake..
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 20

Expert Comment

by:ihenry
ID: 12394646

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
 

Author Comment

by:Johnny
ID: 12395867
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
 
LVL 34

Assisted Solution

by:flavo
flavo earned 750 total points
ID: 12396620
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
 

Author Comment

by:Johnny
ID: 12397158
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
 
LVL 34

Expert Comment

by:flavo
ID: 12397178
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
 

Author Comment

by:Johnny
ID: 12402421
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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

971 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