Jump to content
Sign in to follow this  
supersonic

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

Recommended Posts

supersonic

Hi!

Is there a way to connect (~ bind) two ListView controls to scroll them down at the same time?

I have no idea to realize this, so I have no sample code so far...

Can someone gimme a clue?

Greets,

-supersonic.

Share this post


Link to post
Share on other sites
Melba23

supersonic,

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
supersonic

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

Share this post


Link to post
Share on other sites
picea892

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

Share this post


Link to post
Share on other sites
Mat

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

Share this post


Link to post
Share on other sites
supersonic

Thank you!

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

Share this post


Link to post
Share on other sites
supersonic

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

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
ResNullius

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

Share this post


Link to post
Share on other sites
gcue

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

Share this post


Link to post
Share on other sites
gcue

*bump*

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
gcue

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

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
gcue

ok ill try that ;)

- thanks

Share this post


Link to post
Share on other sites
water

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 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
gcue

cool thanks water! =)

Share this post


Link to post
Share on other sites
water

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  

×