Jump to content
ricky

Search in a ListView

Recommended Posts

Melba23

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


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
ricky

Thanks, I take a look in the help but not correctly, sorry.

Maybe I will have more questions and keep this topic to do it.

Share this post


Link to post
Share on other sites
ricky

It exists something like _WinAPI_FindTextDlg to the ListView?

Share this post


Link to post
Share on other sites
Melba23

ricky03,

Not as far as I know.

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
Melba23

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


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
ricky

Hello,

thanks for your help.

Before your post I tried with a code and it doesn't work. I try with your's and the problem is the same. Could you help me? Maybe I made a mistake.

Please find below the viewer from sysinfolog modified and a log to analyse :

 SysInfoLog_06-04-2015_031159.log

 _SysInfoLogViewer_v2.11.au3

Thanks for your help

Share this post


Link to post
Share on other sites
Melba23

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


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
ricky

Thanks it works better, but  it search only in the first coloumn, why?

Share this post


Link to post
Share on other sites
Melba23

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


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
ricky

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

Share this post


Link to post
Share on other sites
Melba23

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


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
ricky

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

Share this post


Link to post
Share on other sites
Melba23

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

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
ricky

Thanks for the help and for the links, Noe it works

Share this post


Link to post
Share on other sites
Melba23

ricky03,

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

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
ricky

Yes and no. English is not my native language, I need to take time and actually i'm so tired to read it correctly today.

I will give you a feedback ASAP.

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

×