Jump to content

Change Listbox from MultipleSel to Single & back?


Freedom1
 Share

Recommended Posts

Hello All,

I have a multiple selection listbox. I now come up with a need to use it temporarily as a single selection list box. Is it possible to change an existing multiple selection listbox to single selection? And yes, after modifying the single selection listbox I want to change it back to multiple selection.

I've been looking at the "BIT" operations but can't come up with the proper syntax.

Thanks,

Freedom1

Link to comment
Share on other sites

Try looking at GUICtrlSendMsg()

Thanks, read about it but still came up with nothing....my latest try was:

GUICtrlSetStyle ($lbKeywords, -1, $LBS_MULTIPLESEL)

Also tried: $n=GUICtrlSendMsg ($lbKeywords, $LBS_MULTIPLESEL,-1,0)

No luck, can't figure it out. Poor, dumb me.

More help needed.

Freedom1

Link to comment
Share on other sites

Create two listboxes - one multiselect and one singleselect - and hide/show them as you need.

yes, that's an option, but if I could only flip a bit with a single command rather than create, load & unload, then reload, etc....

My guess it can be done easily, but the syntax eludes me. Hope someone can figure it out and post it here.

Freedom1

Link to comment
Share on other sites

"Flipping a bit" is no problem (BitXOR is what you'd need). Problem is that it won't change anything. Most control styles aren't supposed to be changed during runtime. You set them once and roll with it.

If you don't trust me, here's link to listbox styles article at M$DN, which states "After the control has been created, these styles cannot be modified, except as noted."

So I really don't see any other way than the one I posted earlier.

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

"Flipping a bit" is no problem (BitXOR is what you'd need). Problem is that it won't change anything. Most control styles aren't supposed to be changed during runtime. You set them once and roll with it.

If you don't trust me, here's link to listbox styles article at M$DN, which states "After the control has been created, these styles cannot be modified, except as noted."

So I really don't see any other way than the one I posted earlier.

You could detect when an item is selected, say if the mouse is clicked over the list box, then if you want single selection just deselect any other items using _GUICtrlListBox_SetSel. I think that would be easier than keeping two listboxes.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Well, ok, I suppose this would work (although you need to handle LBN_SELCHANGE message if you want this feature to work with keyboard input, GUI_EVENT_PRIMARYDOWN isn't enough for that obviously)...

#include <GUIConstants.au3>
#Include <GuiList.au3>

$gui = GUICreate("Listbox", 300, 250)
$list = GUICtrlCreateList("", 50,20,200,150, $LBS_MULTIPLESEL+$WS_VSCROLL)
Global $bSingleSel = False
GUICtrlSetData(-1, "a|b|c|d|e|f|g")
$cb = GUICtrlCreateCheckbox("Single select", 100, 200, 100)

GUIRegisterMsg(0x0111, "MY_WM_COMMAND")
GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $cb
            _GUICtrlListSelItemRange($list, 0, 0, _GUICtrlListCount($list)-1)
            $bSingleSel = Not $bSingleSel
;~      Case $GUI_EVENT_PRIMARYDOWN
;~          $aCurs = GUIGetCursorInfo()
;~          If $aCurs[4] = $list And $bSingleSel Then
;~              _GUICtrlListSelItemRange($list, 0, 0, _GUICtrlListCount($list)-1)
;~              _GUICtrlListSetSel($list, 1, _GUICtrlListGetCaretIndex($list))
;~          EndIf
    EndSwitch
WEnd

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode    = BitShift($wParam, 16)
    $nID            = BitAnd($wParam, 0x0000FFFF)
    $hCtrl          = $lParam
    If $nID <> $list Then Return $GUI_RUNDEFMSG
    Switch $nNotifyCode
        Case 1;$LBN_SELCHANGE
            If $bSingleSel And _GUICtrlListGetSelCount($nID) > 1 Then
                _GUICtrlListSelItemRange($list, 0, 0, _GUICtrlListCount($list)-1)
                _GUICtrlListSetSel($list, 1, _GUICtrlListGetCaretIndex($list))
            EndIf
    EndSwitch
EndFunc

But it's kind of a hack, and I'm not sure it's that much better than having two listboxes. Unless you have a lot of dynamic items and need to keep them in sync between the boxes.

Then again, I'm not sure why in the world would I need this dynamic changing of selection style that OP wants, so what do I know...

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

Siao,

Its not that I dont trust you. In fact I really appreciate you contributing to this thread and to my understanding of AutoIt and controls.

dynamic changing of selection style.

The reason I need (want) the multi/single select listbox is that I want to be able to add, modify or remove listbox entries for a listbox that within the app is used as a multiselect listbox. The add, modify and remove entry, in my mind are much easier to implement in a single select mode. When the maintenance of the listbox is complete, return to the app in multiselect mode.

Since I havent done listbox maintenance from within another application, the above is the way I thought it would work out fine. I would be using the same listbox existing within the window, hide the edit controls until needed, make them disappear when returning to the main part of the application. Sound wise?

Ive looked for listbox maintenance routines and have found some, but they didnt lend themselves to seamlessly integrate into the main application.

Im always on the lookout for new ways to do things. If anyone has some examples Id sure like to see them.

Ive tried to show you the reasoning behind my need. If I havent been clear let me know.

The code you provided for Flipping a bit looks great and does what I want it to. I'll be integrating it into my app soon.

Thanks again,

Freedom1

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...