Jump to content

selecting a listview item


Recommended Posts

I have two listviews what i had in mind is when i click an item in the 1st listview it will select the same item on the 2nd listview and likewise

here is what i did

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

$hGUI = GUICreate('Read ListView Item', 600, 300)
$hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 300, 268)
$hListView2 = _GUICtrlListView_Create($hGUI, "", 305, 2, 300, 268)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetExtendedListViewStyle($hListView2, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

; Add items
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)

; Add columns
_GUICtrlListView_InsertColumn($hListView2, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView2, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView2, 2, "Column 3", 100)

; Add items
_GUICtrlListView_AddItem($hListView2, "Name", 0)
_GUICtrlListView_AddSubItem($hListView2, 0, "Age", 1)
_GUICtrlListView_AddSubItem($hListView2, 0, "Sex", 2)
_GUICtrlListView_AddItem($hListView2, "Rayze", 1)
_GUICtrlListView_AddSubItem($hListView2, 1, "16", 1)
_GUICtrlListView_AddSubItem($hListView2, 1, "M", 2)
_GUICtrlListView_AddItem($hListView2, "Tristana", 2)
_GUICtrlListView_AddSubItem($hListView2,2, "F", 2)
GUISetState()

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func ListView_Click()


EndFunc   ;==>ListView_Click


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView
    $hWndListView2 = $hListView2
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    If Not IsHWnd($hListView2) Then $hWndListView2 = GUICtrlGetHandle($hListView2)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    ;$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) ; Get id of clicked item
                    If $aHit[0] <> -1 Then ; Check it was an item
                        Local $sText = _GUICtrlListView_GetItemTextString($hListView, $aHit[0]); Read the item text
                        ConsoleWrite($sText & @CRLF) ; Display it
                        _GUICtrlListView_ClickItem($hListView2, $aHit[0])
                        _GUICtrlListView_SetItemSelected($hListView, $aHit[0])
                    EndIf
                    Return 0
            EndSwitch
        Case $hWndListView2
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView2) ; Get id of clicked item
                    If $aHit[0] <> -1 Then ; Check it was an item
                        Local $sText = _GUICtrlListView_GetItemTextString($hListView2, $aHit[0]); Read the item text
                        ConsoleWrite($sText & @CRLF) ; Display it
                        _GUICtrlListView_ClickItem($hListView2, $aHit[0])
                        _GUICtrlListView_SetItemSelected($hListView, $aHit[0])
                    EndIf
                    Return 0
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

the problem here is that the focus goes on the 2nd listview. i tried _GUICtrlListView_ClickItem($hListView, $aHit[0])

but i'm falling under a loop then i tried _GUICtrlListView_SetItemSelected($hListView, $aHit[0]) with no luck.

Work smarter not harder.My First Posted Script: DataBase

Link to comment
Share on other sites

  • Moderators

Ace08,

Your problem is caused by the _GUICtrlListView_ClickItem lines. When you call that function within the handler you reenter the handler again as the WM_NOTIFY event is fired for the other ListView. ;)

I suggest using _GUICtrlListView_SetItemState like this: :alien:

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

Global $fClicked = 0

$hGUI = GUICreate('Read ListView Item', 600, 300)
$hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 300, 268)
_GUICtrlListView_SetTextBkColor($hListView, 0x00FF00)
$hListView2 = _GUICtrlListView_Create($hGUI, "", 305, 2, 300, 268)
_GUICtrlListView_SetTextBkColor($hListView2, 0x00FF00)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetExtendedListViewStyle($hListView2, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

; Add items
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)

; Add columns
_GUICtrlListView_InsertColumn($hListView2, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView2, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView2, 2, "Column 3", 100)

; Add items
_GUICtrlListView_AddItem($hListView2, "Name", 0)
_GUICtrlListView_AddSubItem($hListView2, 0, "Age", 1)
_GUICtrlListView_AddSubItem($hListView2, 0, "Sex", 2)
_GUICtrlListView_AddItem($hListView2, "Rayze", 1)
_GUICtrlListView_AddSubItem($hListView2, 1, "16", 1)
_GUICtrlListView_AddSubItem($hListView2, 1, "M", 2)
_GUICtrlListView_AddItem($hListView2, "Tristana", 2)
_GUICtrlListView_AddSubItem($hListView2,2, "F", 2)
GUISetState()

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func ListView_Click()


EndFunc   ;==>ListView_Click


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView
    $hWndListView2 = $hListView2
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    If Not IsHWnd($hListView2) Then $hWndListView2 = GUICtrlGetHandle($hListView2)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    ;$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) ; Get id of clicked item
                    If $aHit[0] <> -1 Then ; Check it was an item
                        Local $sText = _GUICtrlListView_GetItemTextString($hListView, $aHit[0]); Read the item text
                        ConsoleWrite($sText & @CRLF) ; Display it
                        _GUICtrlListView_SetItemState($hListView, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        _GUICtrlListView_SetItemState($hListView2, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    EndIf
                    Return 0
            EndSwitch
        Case $hWndListView2
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView2) ; Get id of clicked item
                    If $aHit[0] <> -1 Then ; Check it was an item
                        Local $sText = _GUICtrlListView_GetItemTextString($hListView2, $aHit[0]); Read the item text
                        ConsoleWrite($sText & @CRLF) ; Display it
                        _GUICtrlListView_SetItemState($hListView, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        _GUICtrlListView_SetItemState($hListView2, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    EndIf
                    Return 0
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

Note that I coloured the ListViewItems so that you can tell that the item in the non-focused ListView has been selected. :ph34r:

All clear? :huh2:

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

Wow Thanks Melba23. i also added this inside the do until loop so that it will also work when i press arrow down/up however if the records are bigger than the listview the selected items on the 2nd list view cannot be viewed.

here is what i did

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

Global $fClicked = 0
Global $sText, $sText2
$hGUI = GUICreate('Read ListView Item', 600, 300)
$hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 300, 268)
_GUICtrlListView_SetTextBkColor($hListView, 0x00FF00)
$hListView2 = _GUICtrlListView_Create($hGUI, "", 305, 2, 300, 268)
_GUICtrlListView_SetTextBkColor($hListView2, 0x00FF00)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetExtendedListViewStyle($hListView2, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

; Add items
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 4: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 5: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 6: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 7: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 8: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 9: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 10: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 11: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 12: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 13: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 14: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 15: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 16: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 17: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 18: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 19: Col 1", 2)
_GUICtrlListView_AddItem($hListView, "Row 20: Col 1", 2)
; Add columns
_GUICtrlListView_InsertColumn($hListView2, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView2, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView2, 2, "Column 3", 100)

; Add items
_GUICtrlListView_AddItem($hListView2, "Name", 0)
_GUICtrlListView_AddSubItem($hListView2, 0, "Age", 1)
_GUICtrlListView_AddSubItem($hListView2, 0, "Sex", 2)
_GUICtrlListView_AddItem($hListView2, "Rayze", 1)
_GUICtrlListView_AddSubItem($hListView2, 1, "16", 1)
_GUICtrlListView_AddSubItem($hListView2, 1, "M", 2)
_GUICtrlListView_AddItem($hListView2, "Tristana", 2)
_GUICtrlListView_AddSubItem($hListView2,2, "F", 2)
_GUICtrlListView_AddItem($hListView2, "Triton", 3)
_GUICtrlListView_AddItem($hListView2, "Maokai", 4)
_GUICtrlListView_AddItem($hListView2, "Scooby", 5)
_GUICtrlListView_AddItem($hListView2, "Elie", 6)
_GUICtrlListView_AddItem($hListView2, "Lucky", 7)
_GUICtrlListView_AddItem($hListView2, "Spider", 8)
_GUICtrlListView_AddItem($hListView2, "ants", 9)
_GUICtrlListView_AddItem($hListView2, "monkey", 10)
_GUICtrlListView_AddItem($hListView2, "rug", 11)
_GUICtrlListView_AddItem($hListView2, "rum", 12)
_GUICtrlListView_AddItem($hListView2, "rusty", 13)
_GUICtrlListView_AddItem($hListView2, "Rowen", 14)
_GUICtrlListView_AddItem($hListView2, "Remit", 15)
_GUICtrlListView_AddItem($hListView2, "Computer", 16)
_GUICtrlListView_AddItem($hListView2, "Core", 17)
_GUICtrlListView_AddItem($hListView2, "RAM", 18)
_GUICtrlListView_AddItem($hListView2, "Autoit", 19)
GUISetState()

; Loop until user exits
Do
    If $sText <> _GUICtrlListView_GetItemTextString($hListView) Then
        $sText = _GUICtrlListView_GetItemTextString($hListView)
        $RowNum = _GUICtrlListView_GetSelectedIndices($hListView)
        _GUICtrlListView_SetItemState($hListView2, $RowNum, $LVIS_SELECTED, $LVIS_SELECTED)
        _GUICtrlListView_SetItemState($hListView, $RowNum, $LVIS_SELECTED, $LVIS_SELECTED)
        ConsoleWrite($sText & @CRLF)
    EndIf
    If $sText2 <> _GUICtrlListView_GetItemTextString($hListView2) Then
        $sText2 = _GUICtrlListView_GetItemTextString($hListView2)
        $RowNum2 = _GUICtrlListView_GetSelectedIndices($hListView2)
        _GUICtrlListView_SetItemState($hListView, $RowNum2, $LVIS_SELECTED, $LVIS_SELECTED)
        _GUICtrlListView_SetItemState($hListView2, $RowNum2, $LVIS_SELECTED, $LVIS_SELECTED)
        ConsoleWrite($sText2 & @CRLF)
    EndIf
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func ListView_Click()


EndFunc   ;==>ListView_Click


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView
    $hWndListView2 = $hListView2
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    If Not IsHWnd($hListView2) Then $hWndListView2 = GUICtrlGetHandle($hListView2)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    ;$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) ; Get id of clicked item
                    If $aHit[0] <> -1 Then ; Check it was an item
                        Local $sText = _GUICtrlListView_GetItemTextString($hListView, $aHit[0]); Read the item text
                        ConsoleWrite($sText & @CRLF) ; Display it
                        _GUICtrlListView_SetItemState($hListView, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        _GUICtrlListView_SetItemState($hListView2, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    EndIf
                    Return 0
            EndSwitch
        Case $hWndListView2
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView2) ; Get id of clicked item
                    If $aHit[0] <> -1 Then ; Check it was an item
                        Local $sText2 = _GUICtrlListView_GetItemTextString($hListView2, $aHit[0]); Read the item text
                        ConsoleWrite($sText & @CRLF) ; Display it
                        _GUICtrlListView_SetItemState($hListView, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        _GUICtrlListView_SetItemState($hListView2, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    EndIf
                    Return 0
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

here is what happens;

if i press the arrow down i can see the equivalent item on the 2nd list view however if i reach Row17:Col1 until Row20:Col1 i can no longer see its equivalent listviewitem(on the 2listview)until i scroll down the 2nd listview.

Edited by Ace08

Work smarter not harder.My First Posted Script: DataBase

Link to comment
Share on other sites

  • Moderators

Ace08,

The easiest way to solve that problem is to get the 2 Listviews to mirror their scroll positions: ;)

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

Global $fClicked = 0
Global $sText, $sText2

Global $iCurrLvTop1, $iCurrLvTop2

$hGUI = GUICreate('Read ListView Item', 600, 300)
$hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 300, 268)
_GUICtrlListView_SetTextBkColor($hListView, 0x00FF00)
$hListView2 = _GUICtrlListView_Create($hGUI, "", 305, 2, 300, 268)
_GUICtrlListView_SetTextBkColor($hListView2, 0x00FF00)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetExtendedListViewStyle($hListView2, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUISetState()

Global $iLvCount = _GUICtrlListView_GetCounterPage($hListView) - 1

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)
; Add columns
_GUICtrlListView_InsertColumn($hListView2, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView2, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView2, 2, "Column 3", 100)

; Add items

For $i = 0 To 19
    _GUICtrlListView_AddItem($hListView, "Row " & $i, 0)
    _GUICtrlListView_AddItem($hListView2, "Row " & $i, 0)
Next

GUISetState()

; Loop until user exits
Do
    If $sText <> _GUICtrlListView_GetItemTextString($hListView) Then
        $sText = _GUICtrlListView_GetItemTextString($hListView)
        $RowNum = _GUICtrlListView_GetSelectedIndices($hListView)
        _GUICtrlListView_SetItemState($hListView2, $RowNum, $LVIS_SELECTED, $LVIS_SELECTED)
        _GUICtrlListView_SetItemState($hListView, $RowNum, $LVIS_SELECTED, $LVIS_SELECTED)
        ;ConsoleWrite($sText & @CRLF)
    EndIf
    If $sText2 <> _GUICtrlListView_GetItemTextString($hListView2) Then
        $sText2 = _GUICtrlListView_GetItemTextString($hListView2)
        $RowNum2 = _GUICtrlListView_GetSelectedIndices($hListView2)
        _GUICtrlListView_SetItemState($hListView, $RowNum2, $LVIS_SELECTED, $LVIS_SELECTED)
        _GUICtrlListView_SetItemState($hListView2, $RowNum2, $LVIS_SELECTED, $LVIS_SELECTED)
        ;ConsoleWrite($sText2 & @CRLF)
    EndIf

    ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $iLvTop1 = _GUICtrlListView_GetTopIndex($hListView)
    $iLvTop2 = _GUICtrlListView_GetTopIndex($hListView2)

    If $iLvTop1 <> $iCurrLvTop1 Then
        If $iLvTop1 < $iLvTop2 Then
            _GUICtrlListView_EnsureVisible($hListView2, $iLvTop1)
        ElseIf $iLvTop1 > $iLvTop2 Then
            _GUICtrlListView_EnsureVisible($hListView2, $iLvTop1 + $iLvCount)
        EndIf
        $iCurrLvTop1 = $iLvTop1
        $iCurrLvTop2 = $iLvTop1
    ElseIf $iLvTop2 <> $iCurrLvTop2 Then
        If $iLvTop2 < $iLvTop1 Then
            _GUICtrlListView_EnsureVisible($hListView, $iLvTop2)
        ElseIf $iLvTop2 > $iLvTop1 Then
            _GUICtrlListView_EnsureVisible($hListView, $iLvTop2 + $iLvCount)
        EndIf
        $iCurrLvTop1 = $iLvTop2
        $iCurrLvTop2 = $iLvTop2
    EndIf
    ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func ListView_Click()


EndFunc   ;==>ListView_Click


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView
    $hWndListView2 = $hListView2
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    If Not IsHWnd($hListView2) Then $hWndListView2 = GUICtrlGetHandle($hListView2)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    ;$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) ; Get id of clicked item
                    If $aHit[0] <> -1 Then ; Check it was an item
                        Local $sText = _GUICtrlListView_GetItemTextString($hListView, $aHit[0]); Read the item text
                        ;ConsoleWrite($sText & @CRLF) ; Display it
                        _GUICtrlListView_SetItemState($hListView, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED)
                        _GUICtrlListView_SetItemState($hListView2, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED)
                    EndIf
                    Return 0
            EndSwitch
        Case $hWndListView2
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView2) ; Get id of clicked item
                    If $aHit[0] <> -1 Then ; Check it was an item
                        Local $sText2 = _GUICtrlListView_GetItemTextString($hListView2, $aHit[0]); Read the item text
                        ;ConsoleWrite($sText & @CRLF) ; Display it
                        _GUICtrlListView_SetItemState($hListView, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED)
                        _GUICtrlListView_SetItemState($hListView2, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED)

                    EndIf
                    Return 0
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

You should be able to do the same thing by registering the messages sent by the scrollbars so that you do not poll the loop all the time - I will look into that this afternoon if I find the time. :alien:

M23

Edit: See below! :huh2:

Edited by Melba23

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

  • Moderators

Ace08,

Easier than I thought - for once! ;)

You have to look for the $LVN_ENDSCROLL message in WM_NOTIFY - which is already registered (look for the <<<<<<<<<<<<< lines as usual): :huh2:

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

Global $fClicked = 0
Global $sText, $sText2

$hGUI = GUICreate('Read ListView Item', 600, 300)
$hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 300, 268)
ConsoleWrite("1 = " & $hListView & @CRLF)
_GUICtrlListView_SetTextBkColor($hListView, 0x00FF00)
$hListView2 = _GUICtrlListView_Create($hGUI, "", 305, 2, 300, 268)
ConsoleWrite("2 = " & $hListView2 & @CRLF)
_GUICtrlListView_SetTextBkColor($hListView2, 0x00FF00)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetExtendedListViewStyle($hListView2, BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUISetState()

Global $iLvCount = _GUICtrlListView_GetCounterPage($hListView) - 2

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)
; Add columns
_GUICtrlListView_InsertColumn($hListView2, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView2, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView2, 2, "Column 3", 100)

; Add items

For $i = 0 To 19
    _GUICtrlListView_AddItem($hListView, "Row " & $i, 0)
    _GUICtrlListView_AddItem($hListView2, "Row " & $i, 0)
Next

GUISetState()

; Loop until user exits
Do
    If $sText <> _GUICtrlListView_GetItemTextString($hListView) Then
        $sText = _GUICtrlListView_GetItemTextString($hListView)
        $RowNum = _GUICtrlListView_GetSelectedIndices($hListView)
        _GUICtrlListView_SetItemState($hListView2, $RowNum, $LVIS_SELECTED, $LVIS_SELECTED)
        _GUICtrlListView_SetItemState($hListView, $RowNum, $LVIS_SELECTED, $LVIS_SELECTED)
        ;ConsoleWrite($sText & @CRLF)
    EndIf
    If $sText2 <> _GUICtrlListView_GetItemTextString($hListView2) Then
        $sText2 = _GUICtrlListView_GetItemTextString($hListView2)
        $RowNum2 = _GUICtrlListView_GetSelectedIndices($hListView2)
        _GUICtrlListView_SetItemState($hListView, $RowNum2, $LVIS_SELECTED, $LVIS_SELECTED)
        _GUICtrlListView_SetItemState($hListView2, $RowNum2, $LVIS_SELECTED, $LVIS_SELECTED)
        ;ConsoleWrite($sText2 & @CRLF)
    EndIf

Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func ListView_Click()


EndFunc   ;==>ListView_Click


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView
    $hWndListView2 = $hListView2
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    If Not IsHWnd($hListView2) Then $hWndListView2 = GUICtrlGetHandle($hListView2)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    ;$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) ; Get id of clicked item
                    If $aHit[0] <> -1 Then ; Check it was an item
                        Local $sText = _GUICtrlListView_GetItemTextString($hListView, $aHit[0]); Read the item text
                        ;ConsoleWrite($sText & @CRLF) ; Display it
                        _GUICtrlListView_SetItemState($hListView, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED)
                        _GUICtrlListView_SetItemState($hListView2, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED)
                    EndIf
                    Return 0
                Case $LVN_ENDSCROLL ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    $iLvTop1 = _GUICtrlListView_GetTopIndex($hListView)
                    $iLvTop2 = _GUICtrlListView_GetTopIndex($hListView2)
                    If $iLvTop1 < $iLvTop2 Then
                        _GUICtrlListView_EnsureVisible($hListView2, $iLvTop1)
                    ElseIf $iLvTop1 > $iLvTop2 Then
                        _GUICtrlListView_EnsureVisible($hListView2, $iLvTop1 + $iLvCount)
                    EndIf
            EndSwitch
        Case $hWndListView2
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView2) ; Get id of clicked item
                    If $aHit[0] <> -1 Then ; Check it was an item
                        Local $sText2 = _GUICtrlListView_GetItemTextString($hListView2, $aHit[0]); Read the item text
                        ;ConsoleWrite($sText & @CRLF) ; Display it
                        _GUICtrlListView_SetItemState($hListView, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED)
                        _GUICtrlListView_SetItemState($hListView2, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED)

                    EndIf
                    Return 0
                Case $LVN_ENDSCROLL ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    $iLvTop1 = _GUICtrlListView_GetTopIndex($hListView)
                    $iLvTop2 = _GUICtrlListView_GetTopIndex($hListView2)
                    If $iLvTop2 < $iLvTop1 Then
                        _GUICtrlListView_EnsureVisible($hListView, $iLvTop2)
                    ElseIf $iLvTop2 > $iLvTop1 Then
                        _GUICtrlListView_EnsureVisible($hListView, $iLvTop2 + $iLvCount)
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

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

  • Moderators

Ace08,

Do not forget the GUIRegisterMsg tutorial in the Wiki. :huh2:

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

  • 2 weeks later...

Hi sorry for bringing this post back up, i'm having trouble with my scroll bars(down). when scrolling down the listview, it scrolls until the end of the record however when scrolling up it does'nt behave that way. here is what i did

#include <GuiMenu.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <StaticConstants.au3>
#include <GDIPlus.au3>

Opt("TrayIconDebug", 1)

Global $sText,$sText2,$iCurrLvTop1,$iCurrLvTop2,$check,$Start,$End


$hGUI = GUICreate('Read ListView Item', 1000, 620)
$Label1 = "ListView 1"
$lenLabel1 = getTextLengthInPixel($Label1, "Tahoma", 10, 2) ; bold
GUICtrlCreateLabel($Label1, 430, 2, $lenLabel1+30, 20, $ss_leftnowordwrap)
GUICtrlSetFont(-1, 10, 600)
$check = GuiCtrlCreateCheckbox("All", 8, 290, 80, 20)
$Label2 = "ListView 2"
$lenLabel2 = getTextLengthInPixel($Label2, "Tahoma", 10, 2) ; bold
GUICtrlCreateLabel($Label2, 430, 290, $lenLabel2+30, 200, $ss_leftnowordwrap)
GUICtrlSetFont(-1, 10, 600)
$hListView = _GUICtrlListView_Create($hGUI, "", 2, 20,990, 268)
$hListView2 = _GUICtrlListView_Create($hGUI, "", 2, 310,990,268)
$Prev = GUICtrlCreateButton("<<Prev",470,590)
$Next = GUICtrlCreateButton("Next>>",512,590)
$Update = GUICtrlCreateButton("Update",950,590)
_GUICtrlListView_SetExtendedListViewStyle($hListView,  BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT,$LVS_EX_CHECKBOXES))
_GUICtrlListView_SetExtendedListViewStyle($hListView2,  BitOr($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT,$LVS_EX_CHECKBOXES))
GUISetState()

Global $iLvCount = _GUICtrlListView_GetCounterPage($hListView) - 1

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
;~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~ 1st ListView
;~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Col1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Col2", 150)
_GUICtrlListView_InsertColumn($hListView, 2, "Col3", 150)
_GUICtrlListView_InsertColumn($hListView, 3, "Col4", 80)
_GUICtrlListView_InsertColumn($hListView, 4, "Col5", 400)
_GUICtrlListView_InsertColumn($hListView, 5, "Col6", 80)
_GUICtrlListView_InsertColumn($hListView, 6, "Col7", 80)
For $i = 0 to 30
    _GUICtrlListView_AddItem($hListView, "Col1 Row" & $i+1, 0)
    _GUICtrlListView_AddSubItem($hListView, $i, "Col2 Row" & $i+1, 1)
    _GUICtrlListView_AddSubItem($hListView, $i, "Col3 Row" & $i+1, 2)
    _GUICtrlListView_AddSubItem($hListView, $i, "Col4 Row" & $i+1, 3)
    _GUICtrlListView_AddSubItem($hListView, $i, "Col5 Row" & $i+1, 4)
    _GUICtrlListView_AddSubItem($hListView, $i, "Col6 Row" & $i+1, 5)
    _GUICtrlListView_AddSubItem($hListView, $i, "Col7 Row" & $i+1, 6)
Next
;~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~ 2nd ListView
;~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Add columns
_GUICtrlListView_InsertColumn($hListView2, 0, "Col1", 100)
_GUICtrlListView_InsertColumn($hListView2, 1, "Col2", 150)
_GUICtrlListView_InsertColumn($hListView2, 2, "Col3", 150)
_GUICtrlListView_InsertColumn($hListView2, 3, "Col4", 80)
_GUICtrlListView_InsertColumn($hListView2, 4, "Col5", 400)
_GUICtrlListView_InsertColumn($hListView2, 5, "Col6", 80)
_GUICtrlListView_InsertColumn($hListView2, 6, "Col7", 80)
for $y = 0 to 30
; Add items
    _GUICtrlListView_AddItem($hListView2, "Col1 Row" & $i+1, 0)
    _GUICtrlListView_AddSubItem($hListView2, $y, "Col1 Row" & $i+1, 1)
    _GUICtrlListView_AddSubItem($hListView2, $y, "Col1 Row" & $i+1, 2)
    _GUICtrlListView_AddSubItem($hListView2, $y, "Col1 Row" & $i+1, 3)
    _GUICtrlListView_AddSubItem($hListView2, $y, "Col1 Row" & $i+1, 4)
    _GUICtrlListView_AddSubItem($hListView2, $y, "Col1 Row" & $i+1, 5)
    _GUICtrlListView_AddSubItem($hListView2, $y, "Col1 Row" & $i+1, 6)
Next
GUISetState()

; Loop until user exits
while 1
    If $sText <> _GUICtrlListView_GetItemTextString($hListView) Then
        $sText = _GUICtrlListView_GetItemTextString($hListView)
        $RowNum = _GUICtrlListView_GetSelectedIndices($hListView)
        _GUICtrlListView_SetItemState($hListView2, $RowNum, $LVIS_SELECTED, $LVIS_SELECTED)
        _GUICtrlListView_SetItemState($hListView, $RowNum, $LVIS_SELECTED, $LVIS_SELECTED)
    EndIf
    If $sText2 <> _GUICtrlListView_GetItemTextString($hListView2) Then
        $sText2 = _GUICtrlListView_GetItemTextString($hListView2)
        $RowNum = _GUICtrlListView_GetSelectedIndices($hListView2)
        _GUICtrlListView_SetItemState($hListView, $RowNum, $LVIS_SELECTED, $LVIS_SELECTED)
        _GUICtrlListView_SetItemState($hListView2, $RowNum, $LVIS_SELECTED, $LVIS_SELECTED)
    EndIf
    $iLvTop1 = _GUICtrlListView_GetTopIndex($hListView)
    $iLvTop2 = _GUICtrlListView_GetTopIndex($hListView2)
    If $iLvTop1 <> $iCurrLvTop1 Then
        If $iLvTop1 < $iLvTop2 Then
            _GUICtrlListView_EnsureVisible($hListView2, $iLvTop1)
        ElseIf $iLvTop1 > $iLvTop2 Then
            _GUICtrlListView_EnsureVisible($hListView2, $iLvTop1 + $iLvCount)
        EndIf
        $iCurrLvTop1 = $iLvTop1
        $iCurrLvTop2 = $iLvTop1
    ElseIf $iLvTop2 <> $iCurrLvTop2 Then
        If $iLvTop2 < $iLvTop1 Then
            _GUICtrlListView_EnsureVisible($hListView, $iLvTop2)
        ElseIf $iLvTop2 > $iLvTop1 Then
            _GUICtrlListView_EnsureVisible($hListView, $iLvTop2 + $iLvCount)
        EndIf
        $iCurrLvTop1 = $iLvTop2
        $iCurrLvTop2 = $iLvTop2
    EndIf
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
;~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;~ CheckBox (All)
;~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Case $check
            If GUICtrlRead($check) = $GUI_CHECKED Then
                For $checkbox = 0 to $y
                    _GUICtrlListView_SetItemChecked($hListView2, $checkbox)
                Next
            Else
                For $checkbox2 = 0 to $y
                    _GUICtrlListView_SetItemChecked($hListView2, $checkbox2,False)
                Next
            EndIf
    EndSwitch
WEnd

Func ListView_Click()


EndFunc   ;==>ListView_Click


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)

    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo,$OldText
    $hWndListView = $hListView
    $hWndListView2 = $hListView2
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"));$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")

    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) ; Get id of clicked item
                    If $aHit[0] <> -1 Then ; Check it was an item
;~                         $sText = _GUICtrlListView_GetItemTextString($hListView, $aHit[0]); Read the item text once clicked
;~                         ConsoleWrite($sText & @CRLF) ; Display it
                        _GUICtrlListView_SetItemState($hListView, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED)
                        _GUICtrlListView_SetItemState($hListView2, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED)
                    EndIf
                    Return 0
            EndSwitch
        Case $hWndListView2
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView2) ; Get id of clicked item
                    If $aHit[0] <> -1 Then ; Check it was an item
;~                         $sText2 = _GUICtrlListView_GetItemTextString($hListView2, $aHit[0]); Read the item text once clicked
;~                         ConsoleWrite($sText2 & @CRLF) ; Display it
                        _GUICtrlListView_SetItemState($hListView2, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED)
                        _GUICtrlListView_SetItemState($hListView, $aHit[0], $LVIS_SELECTED, $LVIS_SELECTED)
                    EndIf
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func getTextLengthInPixel($text, $font, $size = 9, $style = 0)
    ;Calculate actual width of the given text
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hFamily = _GDIPlus_FontFamilyCreate($font)
    $hGDIFont = _GDIPlus_FontCreate($hFamily, $size, $style)
    $hFormat = _GDIPlus_StringFormatCreate()
    $tLayout = _GDIPlus_RectFCreate(0, 0, @DesktopWidth, @DesktopHeight)

    $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $text, $hGDIFont, $tLayout, $hFormat)
    $width = Int(DllStructGetData($aInfo[0], 3)) + 1

    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontDispose($hGDIFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Return $width
EndFunc

Also i have noticed that if the fields are wide enough to create a left/right scroll bar this happens however if all the fields fit inside, it does not show this kind of behavior. would appreciate if you could tell me whats wrong Thanks in advance :huh2:

Work smarter not harder.My First Posted Script: DataBase

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