CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2001
    Posts
    38

    Help with 2 CheckBoxes

    Hi,

    I have two checkboxes in my form. I want to be able to do this: Only one checkbox can be selected. if one gets selected, the other one shouldnt be (and vice versa)...Also, How do I check to see if it is checked or not? I want to make some controls invisible if checkbox1 gets selected, same for checkbox2,

    Thanks a lot!!


  2. #2
    Join Date
    Jan 2001
    Posts
    165

    Re: Help with 2 CheckBoxes

    Sounds like you should be using option buttons as this is their inherent nature but if you want the look of a checkbox do this:

    private sub Check1_Click(Index as Integer)
    Dim i

    If Check1(Index).Value = 1 then
    for i = Check1.LBound to Check1.UBound
    If i <> Index then Check1(i).Value = 0
    next i
    End If
    End sub



    This is assuming you use an array of checkboxes if not then you will have to copy code to each checkbox click event to set all the other checkboxes to 0.

    To check if a box is checked or not just do:

    if Check1.Value = 1 'or the constant vbChecked

    -K


  3. #3
    Join Date
    Mar 2001
    Posts
    38

    Re: Help with 2 CheckBoxes

    Thanks a lot!!!!

    Maybe you can help me with this too: I have a comboBox that loads all records from field ("SourceFileName")

    If rs Is Nothing Then
    Exit Sub
    End If

    With rs
    'Are there any records?
    If .BOF And .EOF Then
    Exit Sub
    End If

    'Load the control, starting from the record
    'current in the recordset
    Do Until .EOF
    cmbFiles.AddItem .Fields("SourceFileName").Value
    cmbFiles.ItemData(cmbFiles.NewIndex) = .Fields("UploadID").Value
    .MoveNext
    Loop
    End With

    This will display everything in the combobox. Now, I have no idea how to get the Id's for each of the records ("UploadID"); I can actually "get" them, but I need to be able to, based on a selection in the ComBoBox, I will grab the ID("uploadID") from the selected value in the combobox so I can Use it ro perform a query. How can I do this?????????

    Thanks again,

    herick


  4. #4
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: Help with 2 CheckBoxes

    The functionality that you describe is that of the option buttons, but here's a workaround using the checkboxes.

    private Sub Check1_Click()
    Check2.Value = IIf(Check1.Value = vbChecked, vbUnchecked, vbChecked)
    End Sub

    private Sub Check2_Click()
    Check1.Value = IIf(Check2.Value = vbChecked, vbUnchecked, vbChecked)
    End Sub




    To make a control invisible just set the visible property to false as in
    text1.visible = false


    David Paulson

  5. #5
    Join Date
    Jan 2001
    Posts
    165

    Re: Help with 2 CheckBoxes

    in the control's click event put this:

    dim id
    id = cmbFiles.ItemData(cmbFiles.ListIndex)

    This will give you the UploadId that you stored during the additem procedure

    -K


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

Featured