Results 1 to 6 of 6

Thread: using checkbox in lsitbox to save settings ??

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    13

    Question

    HI,

    i'm making a program that wil change registry settings for a user. I want to build in a listbox in checkbox state and the user must be able to click on the item(There by checking it) en then when the press save and the registry settings will be saved. The problem is i dont how how to get selected box's and pass the value's.

    Example.: If a user selected NoFind in the list box i must change the dword HKEY_blab\anotherkey\..\NoFind in to 1
    normaly i would do this like X=savesettings HKEY_blab\anotherkey\..\check1.value (i when use checkboxes)

    But how do i do this with a listbox ??

    Thanx in advance for the help

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    normaly i would do this like X=savesettings HKEY_blab\anotherkey\..\check1.value (i when use checkboxes)

    'if you do it in the click event of the listbox

    If list1.text = "nofind" then
    myVal = 1
    else
    myVal = 0
    End If
    X=savesettings HKEY_blab\anotherkey\..\myVal
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810
    If you want to loop through the ListItems then:
    Code:
        Dim intLoop     As Integer
        Dim intVal   As Integer
    
        For intLoop = 0 To List1.Listcount - 1
            List1.ListIndex = intLoop
            If List1.Selected(intLoop) = True Then
                intVal = 1
            Else
                intVal = 0
            End If
            '// SaveSetting here
        End If
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Jerry, you shouldn't loop through the list, it will slow if the ListBox have a large number of item, try use API.

    Code:
    Dim i As Integer
    Dim Idx As Integer
    Dim sCount As Integer
    Dim sBuff(512) As Long
    
    'Get the number of selected item
    sCount = SendMessage(List1.hwnd, LB_GETSELCOUNT, 0, 0)
    If sCount = 1 Then
        'For Single selection
        Idx = SendMessage(List1.hwnd, LB_GETCURSEL, 0, 0)
        'Paste your save setting into registry code here
        ' [Sample]
        ' "HKEY_blab\anotherkey\..\" & list1.List (idx)
    Else
        'For Multi selection
        If sCount < 512 Then
            Idx = SendMessage(List1.hwnd, LB_GETSELITEMS, 512, sBuff(0))
            For i = Idx - 1 To 0 Step -1
                'Paste your save setting into registry code here
                ' [Sample]
                ' "HKEY_blab\anotherkey\..\" & list1.List (idx)
            Next
        Else
            MsgBox "Too many selected item!", vbExclamation + vbOKOnly, "ListBox"
        End If
    End If

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    13

    Question Will this work for more then one check?

    Thank you all for you help i will try it out, but chris one question will this work for more then one checkbox??

    Because there will be about 13 check boxes (no multi line)
    and each one of then will have a different setting. Would please explain to me how i can do that


    Once again Thanx in Advance

  6. #6
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Just reading it...

    yep Mystic....
    its right in chris' code...
    this section shows the multiselection handling...
    Code:
    .........From chris....
        'For Multi selection
        If sCount < 512 Then
            Idx = SendMessage(List1.hwnd, LB_GETSELITEMS, 512, sBuff(0))
            For i = Idx - 1 To 0 Step -1
                'Paste your save setting into registry code here
                ' [Sample]
                ' "HKEY_blab\anotherkey\..\" & list1.List (idx)
            Next
        Else
            MsgBox "Too many selected item!", vbExclamation + vbOKOnly, "ListBox"
        End If
    .......

    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

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