Jump to content

Scrolling 3 seperate Listboxes


MikahS
 Share

Go to solution Solved by Melba23,

Recommended Posts

Hello AutoIt community,

I have a question for you all. Now, I know using a multi column listbox could do such as my question will ask, but I would like to know this for only multiple single column listbox's.

I have been able to select all three values and scroll the listbox's (I have 3 side by side) to the appropriate value of each column and match them up (only when an item has been selected). My problem is, I'd like the listboxes to scroll together, rather than independently. I have not tried scripting anything to help me do this, but I have taken a look at _GUIScrollBars which had a function called _GUIScrollBars_GetScrollInfoEx. Could the $tagSCROLLINFO structure be used to do this? It's probably due to ignorance that I think this, but could anyone enlighten me? o:)

EDIT: Maybe with _GUIScrollBars_GetScrollInfoTrackPos and _GUIScrollBars_SetScrollInfoPos? Did not work, as ScrollInfoTrackPos only tracks one scrollbar.

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

  • Moderators
  • Solution

MikahS,

How about this for starters? ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>
#include <ScrollBarsConstants.au3>

Global Const $iMax = 40

Global $iPos_1 = 0, $iPos_2 = 0

$hGUI = GUICreate("Synchro Pair", 195, 240)
$cList_2 = GUICtrlCreateList("", 60, 5, 85, 220)

; Dummy to fire when list views are not synced
$cSync = GUICtrlCreateDummy()

GUISetState(@SW_SHOW)

$hGUI_Child = GUICreate("", 50, 220, 10, 5, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
$cList_1 = GUICtrlCreateList("", 0, 0, 85, 220)
GUISetState()

For $i = 1 To $iMax
    _GUICtrlListBox_AddString($cList_1, "1_" & $i)
    _GUICtrlListBox_AddString($cList_2, "2_" & $i)
Next

AdlibRegister("_Synchro")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cSync
            ; Stop Adlib
            AdlibUnRegister("_Synchro")
            ; Scroll List 1
            _GUICtrlListBox_SetTopIndex($cList_1, $iPos_2)
            ; Restart Adlib
            AdlibRegister("_Synchro")
    EndSwitch
WEnd


Func _Synchro()

    ; Get top index of each list
    $iPos_1 = _GUICtrlListBox_GetTopIndex($cList_1)
    $iPos_2 = _GUICtrlListBox_GetTopIndex($cList_2)
    ; Fire dummy
    GUICtrlSendToDummy($cSync)

EndFunc   ;==>_Synchro
There should be a message we can trap rather then using Adlib - I will see what I can develop. :)

M23

Edit:

ListBoxes are primitive beasts - if you wanted to use ListViews it is much more elegant: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <GuiListView.au3>
#include <Misc.au3>
#include <GuiScrollBars.au3>

Global Const $iMax = 40

Global $iPos_1 = 0, $iPos_2 = 0

$hGUI = GUICreate("Synchro Pair", 195, 240, -1, -1)
$cLV_2 = GUICtrlCreateListView("LV_2", 60, 5, 85, 220)
$hLV_2 = GUICtrlGetHandle($cLV_2)
GUISetState(@SW_SHOW)

$hGUI_Child = GUICreate("", 50, 220, 10, 5, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
$cLV_1 = GUICtrlCreateListView("LV_1", 0, 0, 85, 220)
$hLV_1 = GUICtrlGetHandle($cLV_1)
GUISetState()

For $i = 1 To $iMax
    GUICtrlCreateListViewItem("Item " & $i, $cLV_1)
    GUICtrlCreateListViewItem("Item " & $i, $cLV_2)
Next

Global $aRect = _GUICtrlListView_GetItemRect($hLV_2, 0)
Global Const $iDeltaY = $aRect[3] - $aRect[1]
GUIRegisterMsg($WM_NOTIFY, "_WM_Notify")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _WM_Notify($hWnd, $Msg, $wParam, $lParam)
    Local Const $iLines = _SendMessage($hLV_2, $LVM_GETTOPINDEX) - _SendMessage($hLV_1, $LVM_GETTOPINDEX)
    _SendMessage($hLV_1, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>_WM_Notify
Credit to UEZ for this. ;) Edited by Melba23
Found a better function

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I will say, very nice Melba :D

I've been playing with it for a bit and a couple things I noticed, you are right it is easier to do this with ListViews instead of Listboxes ;)

The way I had my Listboxes setup was they each were able to independantly scroll (3 of them) of each other. I thought that I would need to think about that, but after staring at it I can see that that might be trying to do to much, and that I need to make it simplier.

I will update the topic soon with what I have decided should be the best way of doing what I think will be the best readable way of showing the data. I'm also thinking you have completely answered my question if I can do what I might be able to accomplish.

I would love if there was a way to make them all scrollable and still be able to scroll each one and then scroll the rest, whether that be list1, list2, or list3.

I will give this a try myself too.

Thank you for this, again :)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

Again, Melba thanks for the code. :)

Here is what I used once I played around with it for a bit. I have changed the while loop to make sure the $cList_2 will always have focus, so using the scroll wheel is always possible. Also, I made it so the selection in the first box will match and highlight the second box's text value that matches the selected value in the first box, if no selection has been made in the first box and only in the second listbox then highlight both as well. Also added a check between the selected values and if they are already selected, then scroll only.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>
#include <ScrollBarsConstants.au3>

Global Const $iMax = 40

Global $iPos_1 = 0, $iPos_2 = 0

$hGUI = GUICreate("Synchro Pair", 195, 240)
$cList_2 = GUICtrlCreateList("", 60, 5, 85, 220)

; Dummy to fire when list views are not synced
$cSync = GUICtrlCreateDummy()

GUISetState(@SW_SHOW)
$hGUI_Child = GUICreate("", 50, 220, 10, 5, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
$cList_1 = GUICtrlCreateList("", 0, 0, 85, 220)
GUISetState()

For $i = 1 To $iMax
    _GUICtrlListBox_AddString($cList_1, "1_" & $i)
    _GUICtrlListBox_AddString($cList_2, "2_" & $i)
Next

AdlibRegister("_Synchro")

While 1
    If GUICtrlGetState($cList_2) <> 256 Then GUICtrlSetState($cList_2, $GUI_FOCUS) ; make sure $cList_2 always has focus
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cSync
            ; Stop Adlib
            AdlibUnRegister("_Synchro")
            ; Scroll List 1
            _GUICtrlListBox_SetTopIndex($cList_1, $iPos_2)
            ; Restart Adlib
            AdlibRegister("_Synchro")
    EndSwitch
WEnd

Func _Synchro()
    Local $gs, $ss, $ft

    ; Get top index of each list
    $iPos_1 = _GUICtrlListBox_GetTopIndex($cList_1)
    $iPos_2 = _GUICtrlListBox_GetTopIndex($cList_2)
    If _GUICtrlListBox_GetCurSel($cList_1) = _GUICtrlListBox_GetCurSel($cList_2) Then ; if the selections are the same in both listboxes
        GUICtrlSendToDummy($cSync) ; send the message to scroll (event)
        Return ; get out
    Else
        $gs = _GUICtrlListBox_GetCurSel($cList_1) ; get the current selection in $cList_1
        If $gs = -1 Then ; if there is no selection
            $gs = _GUICtrlListBox_GetCurSel($cList_2) ; check $cList_2
            $ss = _GUICtrlListBox_SetCurSel($cList_1, $gs) ; set the currently selected value in $cList_2 to $cList_1
            GUICtrlSendToDummy($cSync) ; send the message to scroll
            Return ; get out
        EndIf
        $ss = _GUICtrlListBox_SetCurSel($cList_2, $gs) ; set the selection in $cList_2
        ; Fire dummy
        GUICtrlSendToDummy($cSync) ; send the message to scroll (event)
    EndIf
EndFunc   ;==>_Synchro
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

  • Moderators

MikahS,

Having seen that I wonder why you do not use a single 2-column ListView - much simpler to code: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Global Const $iMax = 40

$hGUI = GUICreate("ListView", 200, 240)

$cLV = GUICtrlCreateListView(" | ", 10, 10, 180, 220, $LVS_NOCOLUMNHEADER)
_GUICtrlListView_SetColumnWidth($cLV, 0, 78)
_GUICtrlListView_SetColumnWidth($cLV, 1, 78)

For $i = 1 To $iMax
    GUICtrlCreateListViewItem("1_" & $i & "|2_" & $i, $cLV)
Next

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hmm. I've actually never used ListViews before, so I was hesitant to redo all my code, but it just seems everything is easier with a ListView ;)

EDIT: converting everything to a listview, thanks Melba :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

  • Moderators

MikahS,

ListViews are complicated beasts to be sure, but they are much more flexible than simple ListBoxes. If you want a taste of what you can do with them, have a play with the examples in my GUIListViewEx UDF. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Bad wording on my part heh, but I will take a look at your UDF Melba and again, thanks for the exemplary help. :D

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

  • Moderators

MikahS,

My pleasure, as always. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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

×
×
  • Create New...