Jump to content

How to connect two ListView ctrls to scroll them down at the same time???


Recommended Posts

  • Moderators

supersonic,

Why not make a ListView with 2 columns? Seems a lot easier to me! :D

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

M23,

Currently I have one LV.

My idea:

the first (= left) ListView lists our AD-Users.

The second (= right) ListView lists some AD-Attributes

for the users shown in the left LV.

When I scoll the right LV I would like to

know to whom the attributes belong.

Any ideas?

supersonic,

Why not make a ListView with 2 columns? Seems a lot easier to me! :D

M23

Link to comment
Share on other sites

Scrolling first listview scrolls the second...could work vice versa also but did not set it up that way.

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

$iLastPos = IniRead("Test.ini", "Scroll", "VPos", 0)

$GUI = GUICreate("Test Script", 600, 200)

$ListView = GUICtrlCreateListView("Col          ", 20, 20, 260, 160)
$hListView = GUICtrlGetHandle($ListView)

$ListView2 = GUICtrlCreateListView("Col          ", 280, 20, 260, 160)
$hListView2 = GUICtrlGetHandle($ListView2)

For $i = 1 To 80
    GUICtrlCreateListViewItem("Item " & $i, $ListView)
    GUICtrlCreateListViewItem("Next " & $i, $ListView2)
Next

GUISetState(@SW_SHOW, $GUI)

While 1
    Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    if _GUICtrlListView_GetTopIndex($hListView)<_GUICtrlListView_GetTopIndex($hListView2) then 
            _GUICtrlListView_Scroll($hListView2, 0, -12)
    elseif _GUICtrlListView_GetTopIndex($hListView)>_GUICtrlListView_GetTopIndex($hListView2) then 
            _GUICtrlListView_Scroll($hListView2, 0, +12)
    EndIf
    
WEnd
Link to comment
Share on other sites

Heres an example using WM_NOTIFY, which for some odd reason doesn't work perfectly if you shake the scroll bar up and down :D

#include<SendMessage.au3>
#include<WindowsConstants.au3>
#include<StructureConstants.au3>
#include<ListViewConstants.au3>

Global $hGUI, $hList1, $hList2

$hGUI = GUICreate("Testing scroll", 500, 600)

$hList1 = GUICtrlCreateListView("List view 1", 2, 2, 248, 596)

$hList2 = GUICtrlCreateListView("List view 2", 253, 2, 249, 596)

GUISetState()

For $i = 1 To 500
    GUICtrlCreateListViewItem($i, $hList1)
    GUICtrlCreateListViewItem($i, $hList2)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While GUIGetMsg() <> -3
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    If DllStructGetData($tNMHDR, "code") <> $LVN_ENDSCROLL Then Return
    Local $hListFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $tNMLVSCROLL = DllStructCreate($tagNMLVSCROLL, $lParam)

    If $hListFrom = GUICtrlGetHandle($hList1) Then
        GUICtrlSendMsg($hList2, $LVM_SCROLL, DllStructGetData($tNMLVSCROLL, "dx"), DllStructGetData($tNMLVSCROLL, "dy") * 16)
    ElseIf $hListFrom = GUICtrlGetHandle($hList2) Then
        GUICtrlSendMsg($hList1, $LVM_SCROLL, DllStructGetData($tNMLVSCROLL, "dx"), DllStructGetData($tNMLVSCROLL, "dy") * 16)
    EndIf
EndFunc   ;==>WM_NOTIFY
Link to comment
Share on other sites

Thank you! Indead, heavy scrolling will not resync the ListViews.

Never mind, better than nothing! :-)

Heres an example using WM_NOTIFY, which for some odd reason doesn't work perfectly if you shake the scroll bar up and down :D

#include<SendMessage.au3>
#include<WindowsConstants.au3>
#include<StructureConstants.au3>
#include<ListViewConstants.au3>

Global $hGUI, $hList1, $hList2

$hGUI = GUICreate("Testing scroll", 500, 600)

$hList1 = GUICtrlCreateListView("List view 1", 2, 2, 248, 596)

$hList2 = GUICtrlCreateListView("List view 2", 253, 2, 249, 596)

GUISetState()

For $i = 1 To 500
    GUICtrlCreateListViewItem($i, $hList1)
    GUICtrlCreateListViewItem($i, $hList2)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While GUIGetMsg() <> -3
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    If DllStructGetData($tNMHDR, "code") <> $LVN_ENDSCROLL Then Return
    Local $hListFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $tNMLVSCROLL = DllStructCreate($tagNMLVSCROLL, $lParam)

    If $hListFrom = GUICtrlGetHandle($hList1) Then
        GUICtrlSendMsg($hList2, $LVM_SCROLL, DllStructGetData($tNMLVSCROLL, "dx"), DllStructGetData($tNMLVSCROLL, "dy") * 16)
    ElseIf $hListFrom = GUICtrlGetHandle($hList2) Then
        GUICtrlSendMsg($hList1, $LVM_SCROLL, DllStructGetData($tNMLVSCROLL, "dx"), DllStructGetData($tNMLVSCROLL, "dy") * 16)
    EndIf
EndFunc   ;==>WM_NOTIFY

Link to comment
Share on other sites

  • Moderators

supersonic,

the first (= left) ListView lists our AD-Users.

The second (= right) ListView lists some AD-Attributes

If you have the all data on hand to populate both ListViews and the data is synchronised line-to-line before you start any scrolling, I still believe it would be much easier to make a single ListView to hold all the data and make the whole problem moot...... :D

But it is your script - you decide. :huggles:

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

Building on picea892's idea, here is one that doesn't lag when you have a large number of items in the list view:

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

$iLastPos = IniRead("Test.ini", "Scroll", "VPos", 0)

$GUI = GUICreate("Test Script", 600, 200)

$ListView = GUICtrlCreateListView("Col          ", 20, 20, 260, 160)
$hListView = GUICtrlGetHandle($ListView)

$ListView2 = GUICtrlCreateListView("Col          ", 280, 20, 260, 160)
$hListView2 = GUICtrlGetHandle($ListView2)

For $i = 1 To 1000
  GUICtrlCreateListViewItem("Item " & $i, $ListView)
  GUICtrlCreateListViewItem("Next " & $i, $ListView2)
Next

GUISetState(@SW_SHOW, $GUI)

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Exit
  EndSwitch

  $iLvTopItem = _GUICtrlListView_GetTopIndex($hListView)
  $iLv2TopItem = _GUICtrlListView_GetTopIndex($hListView2)
  $iLvVertSpacing = _GUICtrlListView_GetItemSpacingY($hListView2)
  
  _GUICtrlListView_EnsureVisible($hListView2, $iLvTopItem)
  
  If $iLvTopItem < $iLv2TopItem Then
    ;ConsoleWrite("Less Than:" & @TAB & $iLv2TopItem    - $iLvTopItem & @CRLF)
    _GUICtrlListView_EnsureVisible($hListView2, $iLvTopItem - $iLv2TopItem)
  ElseIf $iLvTopItem > $iLv2TopItem Then
    ;ConsoleWrite("Greater Than:" & @TAB & $iLvTopItem  - $iLv2TopItem & @CRLF)
    _GUICtrlListView_Scroll($hListView2, 0, $iLvVertSpacing)
  EndIf
WEnd
Link to comment
Share on other sites

  • 2 years later...

very nice ResNulius, can the same logic exist so it would apply to both scroll bars?

i have two listviews that I would like to scroll simultaneously - i have 2 seperate listviews because different actions can be done to either so that's why i keep them seperate

Link to comment
Share on other sites

Hi gcue,

I would stick with Melba's suggestion. Much easier to code and easy to understand for the user because there is a 1:1 realationship between the AD user and the properties.

Or do you have andy reasons why you need two LVs?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

hey water =)

the script is intended to resolve a list of user account names to person's full names in the other list view. so having them as seperate listviews helps with the usability so that the user can visually seperate the 2 different entities. so thats why i wanted the scroll thing to work, so that both lists scroll at the same time and items that correlate with each other on both lists correspond to each other even when scrolling.

also i have buttons that perform actions on each list - hard to do when you have just one listview

Link to comment
Share on other sites

I change the color of every 2nd listview line to make it easier for the user to read.

I see no problem with bottons acting on different columns of a listview.

Conclusion: It should be easy to keep everything in one listview ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Code snippet how I fill the LV and change the color of every second line

; Create the LV in the GUI
Global $hGUIUserList = GUICtrlCreateListView("OrgEinheit|Name|Kurzzeichen", 8, 24, 313, 630, $LVS_SHOWSELALWAYS)
...
; Fill LV
_GUICtrlListView_BeginUpdate($hGUIUserList)
For $ii = 1 To $asUser[0][0]
    GUICtrlCreateListViewItem($asUser[$ii][0] & "|" & $asUser[$ii][1] & "|" & $asUser[$ii][3], $hGUIUserList)
    If Mod($iRec, 2) = 0 Then GUICtrlSetBkColor(-1, 0xD0DEC7) ; Change color of every second line
Next
_GUICtrlListView_EndUpdate($hGUIUserList)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

If you have further questions I will be glad to help!

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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...