Jump to content

How to search for items on 2 Listviews.


Loc
 Share

Recommended Posts

I am looking to compare item on 2 listviews. Includes: Lv1 and Lv2 Left click on the item in Lv1 and _GUICtrlListview_Selected() on the item in Lv2 when the item is the same. The items here can't be ordered, it's just that the items can be the same

Link to comment
Share on other sites

  • Moderators

MrRow,

And what have you tried that has not worked?

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

Since my code is too long, I made an example

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <GuiListView.au3>
#include <String.au3>
#include <GuiComboBox.au3>
#include <Array.au3>

Local $GUI, $ListView1, $ListView2

$GUI = GUICreate("Test", 567, 441, 192, 124)
GUICtrlCreateLabel("Listview 1", 8, 0, 72, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$ListView1 = GUICtrlCreateListView("String|int", 0, 32, 274, 406)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
_Listview_Additem('Ok')
_Listview_Additem('Calcel')
_Listview_Additem('Text')
_Listview_Additem('Test')
Local $hListView1 = GUICtrlGetHandle($ListView1)
;_______________________________________________________
GUICtrlCreateLabel("Listview 2", 296, 0, 72, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$ListView2 = GUICtrlCreateListView("int|String", 288, 32, 274, 406)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
_Listview_Additem('Text', 'LV2')
_Listview_Additem('Ok', 'LV2')
_Listview_Additem('Test', 'LV2')
_Listview_Additem('Calcel', 'LV2')
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _Listview_Additem($Setitem, $LVSet = 'LV1')
$Rdint = StringFormat("%04d", Random(1000, 9999, 1))
If $LVSet = 'LV1' Then
GUICtrlCreateListViewItem($Setitem & "|" & $Rdint, $ListView1)
ElseIf $LVSet = 'LV2' Then
GUICtrlCreateListViewItem($Rdint & "|" & $Setitem, $ListView2)
EndIf
EndFunc

Func WM_NOTIFY($hWnd, $nMsg, $wParam, $lParam)
    Local $stNmhdr = DllStructCreate("dword;int;int", $lParam), $hWndFrom = DllStructGetData($stNmhdr, 1)
    Local $nNotifyCode = DllStructGetData($stNmhdr, 3)
    Local $hWndListView = $hListView1
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK
                    _LV_SetItemSelected()
            EndSwitch
    EndSwitch
EndFunc

Func _LV_SetItemSelected()
Local $GetClmLV1 = _GUICtrlListView_GetSelectedColumn($ListView1)
Local $GetSltLV1 = _GUICtrlListView_GetSelectedIndices($ListView1)
Local $GetItLV1 = _GUICtrlListView_GetItemTextArray($ListView1,$GetClmLV1);Listview1
Local $GetClmLV2 = _GUICtrlListView_GetSelectedColumn($ListView2)
Local $GetSltLV2 = _GUICtrlListView_GetSelectedIndices($ListView2)
Local $GetItLV2 = _GUICtrlListView_GetItemTextArray($ListView2,$GetClmLV2);Listview2

$Search = $GetItLV1[0] = $GetItLV2[1]
_GUICtrlListView_SetItemSelected($ListView2,$Search)
_GUICtrlListView_EnsureVisible($ListView2, $Search)

EndFunc

;$Search = _GUICtrlListView_FindText($ListView1, $GetIt, $Search)
;_GUICtrlListView_SetItemSelected($ListView1,$Search)
;_GUICtrlListView_EnsureVisible($ListView1, $Search)

 

Link to comment
Share on other sites

  • Moderators

MrRow,

How about this:

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

$GUI = GUICreate("Test", 567, 441, 192, 124)

GUICtrlCreateLabel("Listview 1", 8, 0, 72, 24)
$ListView1 = GUICtrlCreateListView("String|int", 0, 32, 274, 406)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
_Listview_Additem('Ok')
_Listview_Additem('Cancel')
_Listview_Additem('Text')
_Listview_Additem('Test')

$hListView1 = GUICtrlGetHandle($ListView1)

GUICtrlCreateLabel("Listview 2", 296, 0, 72, 24)
$ListView2 = GUICtrlCreateListView("int|String", 288, 32, 274, 406)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)

$hListView2 = GUICtrlGetHandle($ListView2)

_Listview_Additem('Text', 'LV2')
_Listview_Additem('Ok', 'LV2')
_Listview_Additem('Test', 'LV2')
_Listview_Additem('Cancel', 'LV2')

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

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

Func _Listview_Additem($Setitem, $LVSet = 'LV1')
    $Rdint = StringFormat("%04d", Random(1000, 9999, 1))
    If $LVSet = 'LV1' Then
    GUICtrlCreateListViewItem($Setitem & "|" & $Rdint, $ListView1)
    ElseIf $LVSet = 'LV2' Then
    GUICtrlCreateListViewItem($Rdint & "|" & $Setitem, $ListView2)
    EndIf
EndFunc

Func WM_NOTIFY($hWnd, $nMsg, $wParam, $lParam)
    Local $stNmhdr = DllStructCreate("dword;int;int", $lParam), $hWndFrom = DllStructGetData($stNmhdr, 1)
    Local $nNotifyCode = DllStructGetData($stNmhdr, 3)
    Local $hWndListView = $hListView1
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_CLICK
                    _LV_SetItemSelected()
            EndSwitch
    EndSwitch
EndFunc

Func _LV_SetItemSelected()

    ; Determine item clicked in LV1
    $iIndex = _GUICtrlListView_GetSelectedIndices($hListView1, False)
    $sText = _GUICtrlListView_GetItemText($hListView1, $iIndex)
    ; Find equivalent in LV2
    $iIndex = _GUICtrlListView_FindInText($hListView2, $sText)
    ; Highlight item and ensure visible
    _GUICtrlListView_SetItemState($hListView2, $iIndex, $LVIS_SELECTED, $LVIS_SELECTED)
    _GUICtrlListView_EnsureVisible($hListView2, $iIndex)
    _WinAPI_SetFocus($hListView2)

EndFunc

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

  • Recently Browsing   0 members

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