Jump to content

Search in a ListView


Recommended Posts

  • Moderators

ricky03,

A quick look at the Help file (did you do that before posting?) shows that _GUICtrlListView_FindText/FindInText are likely candidates for your search code.

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

ricky03,

Not as far as I know.

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

ricky03,

It does not seem too difficult to get the search working:

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

$sText = "Text to match"

$hGUI = GUICreate("Test", 500, 500)

$cLV= GUICtrlCreateListView("Items in ListView", 10, 10, 480, 300)
For $i = 0 To 99
    If Mod($i, 10) Then
        GUICtrlCreateListViewItem("Item " & $i, $cLV)
    Else
        GUICtrlCreateListViewItem($sText, $cLV)
    EndIf

Next

$cInput = GUICtrlCreateInput($sText, 10, 350, 400, 20)

$cFind = GUICtrlCreateButton("Find", 10, 400, 80, 30)


GUISetState()

$iIndex = -1

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cFind

            $iIndex = _GUICtrlListView_FindText($cLV, $sText, $iIndex, True, True)
            _GUICtrlListView_ClickItem($cLV, $iIndex)
    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

  • Moderators

ricky03,

Firstly, the script uses OnEvent mode and so adding a GUIGetMsg inside the idle loop serves no purpose at all.

Secondly, you need to use the ListView ControlID as the first parameter of the _GUICtrlListView_FindText function call - you were using some other value.

Changing the code as seen in this modified section works fine for me

Local $ID_GUI = GUICreate($strTitle, 900, 500, -1, -1, 0x00CF0000)
Local $LabelSearch = GUICtrlCreateLabel("Enter the text to find in this log:", 10, 10, 150, 20, 0)
Local $TextFind = GUICtrlCreateInput("Text to find", 170, 10, 240, 20)
Local $ButtonSearch = GUICtrlCreateButton("&Search", 420, 10, 80, 20)
GUICtrlSetOnEvent($ButtonSearch, "_Search") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Local $nMsg, $sText = ""
Local $ID_PRB = GUICtrlCreateProgress(10, 10, 200, 10, 1)
GUICtrlSetBkColor($ID_PRB, 0xFFFFFF)
GUISetOnEvent(-3, '_AllExit')
GUISetOnEvent(-5, 'SIL_AutoSizeGUI')
GUISetOnEvent(-6, 'SIL_AutoSizeGUI')
GUISetOnEvent(-12, 'SIL_AutoSizeGUI')

Opt('GUIOnEventMode', 1)
GUISetState(@SW_SHOW, $ID_GUI)
GUIRegisterMsg(0x0024, '_WM_GETMINMAXINFO')
;
_LvScreen()
Global $init = -1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;
While 1
    Sleep(10) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
WEnd



Func _Search() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $sText = GUICtrlRead($TextFind)
    $init = _GUICtrlListView_FindText($ID_LV, $sText, $init, True, False)
    _GUICtrlListView_ClickItem($ID_LV, $init)
EndFunc

How about for you?

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

ricky03,

There is a wonderful Help file provided with AutoIt - go and read the page for _GUICtrlListView_FindText and you will get the answer (to which incidentally I gave you a very good hint in the first post I made in this thread).

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

Now it works, thansk for your help.

Func _Search()
    ; #include <ColorConstants.au3>
    Local $COLOR_BLACK = 0x000000
    Local $COLOR_RED = 0xFF0000

    GUICtrlSetColor($TextFind, $COLOR_BLACK)
    Local $sText = GUICtrlRead($TextFind)
    $SearchInit = _GUICtrlListView_FindInText($ID_LV, $sText, $SearchInit)
    If $SearchInit = -1 Then
        GUICtrlSetColor($TextFind, $COLOR_RED)
    Else
        _GUICtrlListView_ClickItem($ID_LV, $SearchInit)
    EndIf
EndFunc   ;==>_Search

Now I manage if nothing is found, but how to focus on the first line if nothing is found?

I tried with the code below, but of course the line is highlighted and selected.

_GUICtrlListView_ClickItem($ID_LV, 0)

If nothing found, the text in the iput is red, but how to change the color if we write a new entrie in the input? I try with GUICtrlSetOnEvent with the input, but it doesn't work!

Who can help me?

Thanks in advance

Link to comment
Share on other sites

  • Moderators

ricky03,

Change this section:

Opt('GUIOnEventMode', 1)
GUISetState(@SW_SHOW, $ID_GUI)
GUIRegisterMsg($WM_GETMINMAXINFO, '_WM_GETMINMAXINFO')
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;
_LvScreen()
Global $init = -1
;
While 1
    Sleep(10)
WEnd

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    ; If something has changed in the input
    If BitAND($wParam, 0xFFFF) = $TextFind And BitShift($wParam, 16) = $EN_CHANGE Then
        ; Set colour to black
        GUICtrlSetColor($TextFind, $COLOR_BLACK)
    EndIf

EndFunc   ;==>_WM_COMMAND ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Func _Search()
    $sText = GUICtrlRead($TextFind)
    $init = _GUICtrlListView_FindInText($ID_LV, $sText, $init, False, False)
    If $init = -1 Then
        ; Set colour to red
        GUICtrlSetColor($TextFind, $COLOR_RED)
        ; Ensure top item_is visible
        _GUICtrlListView_EnsureVisible($ID_LV, 0)
    Else
        _GUICtrlListView_ClickItem($ID_LV, $init)
    EndIf
EndFunc

Please ask if you have any questions.

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

This variable $EN_CHANGE not declared, what is this?

Where can I found a help about your function WM_COMMAND? I don't understand the If tests.

Edited by ricky03
Link to comment
Share on other sites

  • Moderators

ricky03,

As l3ill has pointed out, the Help file does exist and is very comprehensive.  But to answer these particular questions:

- You need to include EditConstants.au3, my error for not making that clear.

- I suggest reading the GUIRegisterMsg tutorial in the Wiki to get a basic understanding of Windows messaging.

M23

 

Edited by Melba23
Wrong button, too soon

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

ricky03,

Delighted to hear it. Did you find the tutorial easy to follow?

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