Solved

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

Posted on 2004-10-24
202 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
Question by:Johnny
    9 Comments
     
    LVL 20

    Accepted Solution

    by:
    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
    Forgot to mention,
    The Check_Clicked event is triggered when the checkbox is clicked.
    0
     
    LVL 20

    Expert Comment

    by:ihenry

    Another things..my suggestion won't work if you're working on Windows Form... forgot to ask, my mistake..
    0
     
    LVL 20

    Expert Comment

    by:ihenry

    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
    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
    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
    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
    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
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    This video is in connection to the article "The case of a missing mobile phone (https://www.experts-exchange.com/articles/28474/The-Case-of-a-Missing-Mobile-Phone.html)". It will help one to understand clearly the steps to track a lost android phone.
    Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

    875 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

    12 Experts available now in Live!

    Get 1:1 Help Now