Jump to content

How to filter (search) to the workers and properties?


Recommended Posts

Example code with GUI and an exaple search 

You can download GUIListViewEx.au  that is necessary to run the script

 

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIListViewEx.au3"
#include <Array.au3>

Global $iCount_Left = 20, $vData, $sMsg, $aLV_List_Left, $aLV_List_Right, $aRet, $iEditMode = 0

; Create GUI
$hGUI = GUICreate("LVEx Example 1", 640, 510)

$PeopleNUM = 10
$DataNum = 4

Local $People[$PeopleNUM][$DataNum] = [["Peter", "peter@mycompany.com", "+10", "Boss"] _
        , ["Tom", "Tom@mycompany.com", "+10", "Boss"] _
        , ["Adam", "Adam@mycompany.com", "+10", "Manager"] _
        , ["Mark", "Mark@mycompany.com", "+10", "Manager"] _
        , ["John", "John@mycompany.com", "+10", "Manager"] _
        , ["Dava", "John@mycompany.com", "+10", "Developer"] _
        , ["Marta", "Marta@mycompany.com", "+10", "Tester"] _
        , ["Emilia", "Emilia@mycompany.com", "+10", "Tester"] _
        , ["Sample1", "Sample1@mycompany.com", "+10", "Tester"] _
        , ["Sample2", "Sample2@@mycompany.com", "+10", "New"]]


; Create Right ListView
GUICtrlCreateLabel("UDF ListView", 10, 5, 300, 30)

$hListView_Right = _GUICtrlListView_Create($hGUI, "", 10, 40, 500, 300, BitOR($LVS_DEFAULT, $WS_BORDER))
_GUICtrlListView_SetExtendedListViewStyle($hListView_Right, $LVS_EX_FULLROWSELECT)
_GUICtrlListView_AddColumn($hListView_Right, "Name", 83)
_GUICtrlListView_AddColumn($hListView_Right, "E-mail", 83)
_GUICtrlListView_AddColumn($hListView_Right, "Phone", 83)
_GUICtrlListView_AddColumn($hListView_Right, "title", 83)

_GUICtrlListView_SetTextBkColor($hListView_Right, 0xDDFFDD)

; Fill Right ListView
For $i = 0 To $PeopleNUM - 1
        _GUICtrlListView_AddItem($hListView_Right, $People[$i][0])
    For $j = 0 To $DataNum - 1
        _GUICtrlListView_AddSubItem($hListView_Right, $i, $People[$i][$j], $j)

    Next
Next

; Read array from Right  ListView
Global $aLV_List_Right = _GUIListViewEx_ReadToArray($hListView_Right, 1)


; Initiate LVEx - use read content as array - count parameter set - red insert mark - drag image - move edit by click + headers editable
$iLV_Right_Index = _GUIListViewEx_Init($hListView_Right, $aLV_List_Right, 1, 0xFF0000, True, 4 + 8)
; All columns editable - simple text selected on open
_GUIListViewEx_SetEditStatus($iLV_Right_Index, "*")

; Create buttons
$cInsert_Button = GUICtrlCreateButton("Insert", 10, 350, 200, 30)
$cDelete_Button = GUICtrlCreateButton("Delete", 10, 390, 200, 30)
$cUp_Button = GUICtrlCreateButton("Move Up", 220, 350, 200, 30)
$cDown_Button = GUICtrlCreateButton("Move Down", 220, 390, 200, 30)
;$cEdit_Left_Button = GUICtrlCreateButton("Edit Left 1,1", 10, 430, 200, 30)

$SearchInput = GUICtrlCreateInput("Search", 10, 430, 200, 30)
$SearchButton = GUICtrlCreateButton("Search", 220, 430, 200, 30)

$cDisplay_Right_Button = GUICtrlCreateButton("Show Right", 530, 350, 100, 30)
$cExit_Button = GUICtrlCreateButton("Exit", 430, 390, 200, 110)

; Register for sorting, dragging and editing
_GUIListViewEx_MsgRegister()

GUISetState()

; Set the left ListView as active
; _GUIListViewEx_SetActive(1)

Switch _GUIListViewEx_GetActive()
    Case 0
        $sMsg = "No ListView is active"
    Case 1
        $sMsg = "The LEFT ListView is active" & @CRLF & "<--------------------------"
    Case 2
        $sMsg = "The RIGHT ListView is active" & @CRLF & "---------------------------->"
EndSwitch
;MsgBox(0, "Active ListView", $sMsg)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $cExit_Button
            Exit

        Case $cDelete_Button
            _GUIListViewEx_Delete()

        Case $cUp_Button
            _GUIListViewEx_Up()

        Case $cDown_Button
            _GUIListViewEx_Down()



        Case $cDisplay_Right_Button

            $aLV_List_Right = _GUIListViewEx_ReturnArray($iLV_Right_Index)
            If Not @error Then
                _ArrayDisplay($aLV_List_Right, "Returned Right")
            Else
                MsgBox(0, "Right", "Empty Array")
            EndIf

        Case $SearchButton
            $inputValue = GUICtrlRead($SearchInput)
            SearchInArray($People,$inputValue)

    EndSwitch

    $vRet = _GUIListViewEx_EventMonitor($iEditMode) ; Use combos to change EditMode
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error)
    EndIf
    Switch @extended
        Case 0
            ; No event detected
        Case 1
            If $vRet = "" Then
                MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF)
            Else
                _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " content edited", Default, 8)
            EndIf
        Case 2
            If $vRet = "" Then
                MsgBox($MB_SYSTEMMODAL, "Header edit", "Header edit aborted" & @CRLF)
            Else
                _ArrayDisplay($vRet, "ListView " & _GUIListViewEx_GetActive() & " header edited", Default, 8)
            EndIf
        Case 3
            MsgBox($MB_SYSTEMMODAL, "Sorted", "ListView: " & $vRet & @CRLF)
        Case 4
            MsgBox($MB_SYSTEMMODAL, "Dragged", "From:To" & @CRLF & $vRet & @CRLF)
    EndSwitch

WEnd


Func SearchInArray($array, $valueToSearch)
    $Found = _ArraySearch($array, $valueToSearch, 0, 0, 0, 1)
    MsgBox($MB_ICONINFORMATION, "Found", "I have found in " & $Found & " row!")
    _GUICtrlListView_SetItemFocused($hListView_Right, $Found - 1)
    ;_GUICtrlListViewSetItemSelState($hListView_Right,$Found-1)

EndFunc   ;==>SearchInArray

I would add a feature to my sript if I search for a worker for exaple boss, the view list the Bosses only.

Or If I try to list the e-mails with @mycompany.com.

You can try listing feature if you type  get-ChildItem | Out-GridView to PowerShell, and there is a filter field.

I try to implement something like this filter field.

Thank you very much your assistance any idea would be appriciated. :)

Link to post
Share on other sites
  • Moderators

DannyJ,

Use the latest function to be added to the UDF:

Func SearchInArray($array, $valueToSearch)
    $Found = _ArraySearch($array, $valueToSearch, 0, 0, 0, 1)
    MsgBox($MB_ICONINFORMATION, "Found", "I have found in " & $Found & " row!")
    ; Highlight the row
    _GUIListViewEx_SelectItem($Found)
EndFunc   ;==>SearchInArray

And I suggest changing the search input to use a cue banner like this:

; Do not forget this line at the top:
#include <GuiEdit.au3>

; And then do this:
$SearchInput = GUICtrlCreateInput("", 10, 430, 200, 30)
_GUICtrlEdit_SetCueBanner($SearchInput, "Enter Search Term")
$SearchButton = GUICtrlCreateButton("Search", 220, 430, 200, 30)

Now the cue text disappears when you focus the input - looks a lot better.

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 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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...