Results 1 to 10 of 10

Thread: Leaving Checkbox checked

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    68

    Leaving Checkbox checked

    Hi.

    In my Form i have 5 tabs and each tabpage has some check box,s in them, now what i need to do is that if a check box is check or unchecked and the user goes to another tabpage then back to the first tabpage the checkbox is still checked or unchecked.

    How to i achieve this please?

    Many Thanks

    Worf


    Private Sub AddConPanel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddConPanel.CheckedChanged



    End Sub

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Leaving Checkbox checked

    I'm not sure what the problem is - if you have a form with 5 tab pages, each containing a check box, each tab page's checkbox will retain its value regardless of which tab is displayed.

    Can you elaborate?

  3. #3
    Addicted Member AnthonyGrimes's Avatar
    Join Date
    Sep 2008
    Location
    United States
    Posts
    131

    Re: Leaving Checkbox checked

    What you are asking should be the default behavior. The checkbox controls are independent of each other.

    I am assuming you are using the TabControl.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    68

    Re: Leaving Checkbox checked

    Thanks for replies.

    Sorry, but what i meant to have said was if i left the form with the tabpages on to another form then back again. I need the checkbox's kept set to what the user selected.

    thanks

    Work

  5. #5
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Leaving Checkbox checked

    So long as you don't close down the form it will retain the state of checkboxes. If you are closing the form then you will need to store the values of the checkboxes somewhere and then retrieve them when you re-load the form.

    Depending on the nature of the data and the application you could store these values in a database, in the registry, a configuration file or an object in memory.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    68

    Re: Leaving Checkbox checked

    This is what i have tried but for somereason it does not seem to work.
    The code below is how i have done it, not sure if it is correct.

    All the variables and data strings are all defined in a Module.vb named Data as most of the forms in my application need to read there values and use any data set in some strings.

    'AddControlPanel' is defined in the Module.vb as

    Public AddControlPanel As Integer = 0


    ' Main Form Page


    Public Class Tweaks
    Inherits System.Windows.Forms.Form

    Public Sub Checkstatus()
    If AddControlPanel = 1 Then
    AddConPanel.Checked = True

    End If

    End Sub


    Public Sub AddConPanel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddConPanel.CheckedChanged

    If AddConPanel.Checked = True Then
    AddControlPanel = 1

    Else
    If AddConPanel.Checked = False Then
    AddControlPanel = 0
    End If
    End If


    End Sub

    End Class

  7. #7
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: Leaving Checkbox checked

    A bit hard to tell just from those snippets, but presumably you are calling the CheckStatus procedure whenever the form is shown? Have you put a breakpoint in that routine to check that the routine is actually being run when you are expecting it to?
    Last edited by keystone_paul; Dec 5th, 2008 at 11:05 AM.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Leaving Checkbox checked

    That looks reasonable as it is. Is there code in the Load event, or somewhere like that which calls the CheckStatus sub?
    My usual boring signature: Nothing

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Leaving Checkbox checked

    Yeah, what Pennsylvania Paul said.
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Nov 2008
    Posts
    68

    Re: Leaving Checkbox checked

    Thanks all, put a call into the load event and now it is working.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width