Valnurat

Listview search

5 posts in this topic

I have 8 listview on my GUI. I would like to search in the listview for a number. I only want to search in 3 of the 8 listviews. I know number 1 is in $hLV_C1 and not in the others, but when I run this the result is that that I get the message that it is found in all of my 3 listviews I want to search for.

Global $aSearchListview[3] = ["$hLV_C1","$hLV_C3","$hLV_C5"]
    $hLV_C1 = GUICtrlCreateListView('0', 245, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER, $WS_EX_TRANSPARENT)
    _GUICtrlListView_SetColumnWidth($hLV_C1, 0, $LVSCW_AUTOSIZE)
    $hLV_C2 = GUICtrlCreateListView('0', 275, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER, $WS_EX_TRANSPARENT)
    _GUICtrlListView_SetColumnWidth($hLV_C2, 0, $LVSCW_AUTOSIZE)
    $hLV_C3 = GUICtrlCreateListView('0', 305, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER, $WS_EX_TRANSPARENT)
    _GUICtrlListView_SetColumnWidth($hLV_C3, 0, $LVSCW_AUTOSIZE)
    $hLV_C4 = GUICtrlCreateListView('0', 335, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER, $WS_EX_TRANSPARENT)
    _GUICtrlListView_SetColumnWidth($hLV_C4, 0, $LVSCW_AUTOSIZE)
    $hLV_C5 = GUICtrlCreateListView('0', 365, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER, $WS_EX_TRANSPARENT)
    _GUICtrlListView_SetColumnWidth($hLV_C5, 0, $LVSCW_AUTOSIZE)
    $hLV_C6 = GUICtrlCreateListView('0', 395, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER, $WS_EX_TRANSPARENT)
    _GUICtrlListView_SetColumnWidth($hLV_C6, 0, $LVSCW_AUTOSIZE)
    $hLV_C7 = GUICtrlCreateListView('0', 425, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER, $WS_EX_TRANSPARENT)
    _GUICtrlListView_SetColumnWidth($hLV_C7, 0, $LVSCW_AUTOSIZE)

    
    Local $sNumber = '1', $g_bSortSense = false
    GUICtrlCreateListViewItem($sNumber, $hLV_C1)
    _GUICtrlListView_SimpleSort($hLV_C1,$g_bSortSense,0,False)
    For $iColumnIndex = 0 to UBound($aSearchListview) -1
        Local $iIndex = _GUICtrlListView_FindItem($aSearchListview[$iColumnIndex],-1,$sNumber)
        If $iIndex <> -1 Then
            MsgBox(0,'Found',$aSearchListview[$iColumnIndex])
        Else
            MsgBox(0,'Not Found',$aSearchListview[$iColumnIndex])
        EndIf
    Next

Why is that?


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites



Please, make a full runable with populated LV's (reproducer) script showing your issue(s).

Share this post


Link to post
Share on other sites
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Local $aGUT[0]
Local $aSearchListview[3] = ["$hLV_C1","$hLV_C3","$hLV_C5"]
Local $MainGUIForm = GUICreate("My GUI",455,600)
Local $hHeader, $sNumber, $g_bSortSense = False

    For $i = 0 To 90
        _ArrayAdd($aGUT, $i)
    Next
    GUICtrlCreateTabItem("R/B")
    $hLV_RB = GUICtrlCreateListView('Test', 50, 100, 94, 255, $LVS_NOCOLUMNHEADER)

    ; Now calculate ListView 2 vertical size
    $hHeader = _GUICtrlListView_GetHeader($hLV_RB)
    $aSize = WinGetPos($hHeader)
    $iHeaderHeight = $aSize[3] ; Header height
    $aRect = _GUICtrlListView_GetItemRect($hLV_RB, 0)
    $iItemHeight = $aRect[3] - $aRect[1] ; Item height
    $iTotalHeight = $iHeaderHeight + (20 * ($iItemHeight + .5)) -10 ; Allow for the inter-item gaps
    $hLV_C0 = GUICtrlCreateListView('0', 185, 40, 50, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C0, 0, $LVSCW_AUTOSIZE)
    For $i = 0 To 12
        GUICtrlCreateListViewItem( $i, $hLV_C0)
    Next
    $hLV_C1 = GUICtrlCreateListView('0', 245, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C1, 0, $LVSCW_AUTOSIZE)
    $hLV_C2 = GUICtrlCreateListView('0', 275, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C2, 0, $LVSCW_AUTOSIZE)
    $hLV_C3 = GUICtrlCreateListView('0', 305, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C3, 0, $LVSCW_AUTOSIZE)
    $hLV_C4 = GUICtrlCreateListView('0', 335, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C4, 0, $LVSCW_AUTOSIZE)
    $hLV_C5 = GUICtrlCreateListView('0', 365, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C5, 0, $LVSCW_AUTOSIZE)
    $hLV_C6 = GUICtrlCreateListView('0', 395, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C6, 0, $LVSCW_AUTOSIZE)
    $hLV_C7 = GUICtrlCreateListView('0', 425, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C7, 0, $LVSCW_AUTOSIZE)

Local $id0 = GUICtrlCreatePic("C:\Program Files (x86)\AutoIt3\Examples\GUI\logo4.gif", 0, 0, 169, 68)


GUISetState(@SW_SHOW)

$bProceed = False
Do
    $idMsg = GUIGetMsg()
    Switch $idMsg
        Case $id0
            $sNumber = '1'
            $bProceed = True
    EndSwitch
    If $bProceed Then
        $iIndex = _ArraySearch($aGUT, $sNumber)
        If $iIndex <> - 1 Then
            ; Delete it
            _ArrayDelete($aGUT, $iIndex)
            ; Now clear ListViews 0
            _GUICtrlListView_BeginUpdate($hLV_C0)
            _GUICtrlListView_DeleteAllItems($hLV_C0)
            ; And reload with all / the top 20 elements in the main array
            For $i = 0 To UBound($aGUT) - 1
                If $i < 13 Then
                    GUICtrlCreateListViewItem($aGUT[$i], $hLV_C0)
                EndIf
            Next
            _GUICtrlListView_EndUpdate($hLV_C0)
            GUICtrlCreateListViewItem($sNumber, $hLV_C1)
            _GUICtrlListView_SimpleSort($hLV_C1,$g_bSortSense,0,False)
        Else
            For $iColumnIndex = 0 to UBound($aSearchListview) -1
                Local $iIndex = _GUICtrlListView_FindItem($aSearchListview[$iColumnIndex],-1,$sNumber)
                If $iIndex <> -1 Then
                    MsgBox(0,'Found',$aSearchListview[$iColumnIndex])
                Else
                    MsgBox(0,'Not Found',$aSearchListview[$iColumnIndex])
                EndIf
            Next
        EndIf
        $bProceed = False
        $sNumber = ''
    EndIf
Until $idMsg = $GUI_EVENT_CLOSE

This will produce the error. I'm searching in listview ["$hLV_C1","$hLV_C3","$hLV_C5"], but I know that my number is only in $hLV_C1 2nd time I press the AutoIT logo.

 

Press AutoIT logo and you will see number 2 is moved from one LV0 to LV1.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
  1. your array $aSearchListview holds strings, it must be the ControlID's
  2. _GUICtrlListView_FindItem is not the func you need use _GUICtrlListView_FindText
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Local $aGUT[0]
Local $aSearchListview[3] = ["$hLV_C1","$hLV_C3","$hLV_C5"]
Local $MainGUIForm = GUICreate("My GUI",455,600)
Local $hHeader, $sNumber, $g_bSortSense = False

    For $i = 0 To 90
        _ArrayAdd($aGUT, $i)
    Next
    GUICtrlCreateTabItem("R/B")
    $hLV_RB = GUICtrlCreateListView('Test', 50, 100, 94, 255, $LVS_NOCOLUMNHEADER)

    ; Now calculate ListView 2 vertical size
    $hHeader = _GUICtrlListView_GetHeader($hLV_RB)
    $aSize = WinGetPos($hHeader)
    $iHeaderHeight = $aSize[3] ; Header height
    $aRect = _GUICtrlListView_GetItemRect($hLV_RB, 0)
    $iItemHeight = $aRect[3] - $aRect[1] ; Item height
    $iTotalHeight = $iHeaderHeight + (20 * ($iItemHeight + .5)) -10 ; Allow for the inter-item gaps
    $hLV_C0 = GUICtrlCreateListView('0', 185, 40, 50, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C0, 0, $LVSCW_AUTOSIZE)
    For $i = 0 To 12
        GUICtrlCreateListViewItem( $i, $hLV_C0)
    Next
    $hLV_C1 = GUICtrlCreateListView('0', 245, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C1, 0, $LVSCW_AUTOSIZE)
    $hLV_C2 = GUICtrlCreateListView('0', 275, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C2, 0, $LVSCW_AUTOSIZE)
    $hLV_C3 = GUICtrlCreateListView('0', 305, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C3, 0, $LVSCW_AUTOSIZE)
    $hLV_C4 = GUICtrlCreateListView('0', 335, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C4, 0, $LVSCW_AUTOSIZE)
    $hLV_C5 = GUICtrlCreateListView('0', 365, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C5, 0, $LVSCW_AUTOSIZE)
    $hLV_C6 = GUICtrlCreateListView('0', 395, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C6, 0, $LVSCW_AUTOSIZE)
    $hLV_C7 = GUICtrlCreateListView('0', 425, 40, 25, $iTotalHeight, $LVS_NOCOLUMNHEADER)
    _GUICtrlListView_SetColumnWidth($hLV_C7, 0, $LVSCW_AUTOSIZE)

Local $id0 = GUICtrlCreatePic("C:\Program Files (x86)\AutoIt3\Examples\GUI\logo4.gif", 0, 0, 169, 68)
$aSearchListview[0]=$hLV_C1
$aSearchListview[1]=$hLV_C3
$aSearchListview[2]=$hLV_C5

GUISetState(@SW_SHOW)

$bProceed = False
Do
    $idMsg = GUIGetMsg()
    Switch $idMsg
        Case $id0
            $sNumber = '1'
            $bProceed = True
    EndSwitch
    If $bProceed Then
        $iIndex = _ArraySearch($aGUT, $sNumber)
        If $iIndex <> - 1 Then
            ; Delete it
            _ArrayDelete($aGUT, $iIndex)
            ; Now clear ListViews 0
            _GUICtrlListView_BeginUpdate($hLV_C0)
            _GUICtrlListView_DeleteAllItems($hLV_C0)
            ; And reload with all / the top 20 elements in the main array
            For $i = 0 To UBound($aGUT) - 1
                If $i < 13 Then
                    GUICtrlCreateListViewItem($aGUT[$i], $hLV_C0)
                EndIf
            Next
            _GUICtrlListView_EndUpdate($hLV_C0)
            GUICtrlCreateListViewItem($sNumber, $hLV_C1)
            _GUICtrlListView_SimpleSort($hLV_C1,$g_bSortSense,0,False)
        Else
            For $iColumnIndex = 0 to UBound($aSearchListview) -1
                Local $iIndex = _GUICtrlListView_FindText($aSearchListview[$iColumnIndex],$sNumber,-1,False)
                If $iIndex <> -1 Then
                    MsgBox(0,'Found',$aSearchListview[$iColumnIndex])
                Else
                    MsgBox(0,'Not Found',$aSearchListview[$iColumnIndex])
                EndIf
            Next
        EndIf
        $bProceed = False
        $sNumber = ''
    EndIf
Until $idMsg = $GUI_EVENT_CLOSE

your Piccontrol can cause troubles: if the path to pic is incorect a endless searching is done.

Share this post


Link to post
Share on other sites

Aha, of course. Doh.

 

Thank you.


Yours sincerely

Kenneth.

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

  • Similar Content

    • Gorby7
      By Gorby7
      I have an Autoit-based client GUI that uses a single MS SQL Server database. I have no problem connecting to and executing queries against this database from my AutoIT code, with the below exception:
      One of the database's stored procedures I need to execute requires a parameter that is a table. I've set up the appropriate table_type on the database and everything works fine on the database itself when I execute the stored proc with a table variable for the parameter (no AutoIT involved). The problem is that I can't figure out how to pass a table parameter from AutoIT, assuming it's even possible. The code below shows the two methods I've tried, both methods return a RecordSet object that is at EOF.
      #include <Array.au3> Opt("MustDeclareVars", 0) $sDBSrv = "ITSQL01.domain.com" $sDBName = "INVDEV" $sADOName = "ADODB.Connection" $oSQLConn = ObjCreate($sADOName) $sConnStr = "Driver={SQL Server};Server=" & $sDBSrv & ";Database=" & $sDBName & ";Trusted_Connection=yes;" $oSQLConn.Open ($sConnStr) $rsoFacFriendly = $oSQLConn.Execute("SELECT TOP 5 FriendlyName FROM Facility") If Not $rsoFacFriendly.EOF Then $aFacFriendly = $rsoFacFriendly.GetRows() _ArrayDisplay($aFacFriendly) $rsoSPResults = $oSQLConn.Execute("EXEC spTableParameterPassTest " & $aFacFriendly) Select Case $rsoSPResults.EOF = False MsgBox(0, "sp exec1", "not end of file") $aSPResults = $rsoSPResults.GetRows() _ArrayDisplay($aSPResults) Case IsObj($rsoSPResults) = 0 MsgBox(0, "sp exec1", "rso isn't even an object") Case $rsoSPResults.EOF = True MsgBox(0, "sp exec1", "At end of file") Case Else MsgBox(0, "sp exec1", "Something else happened") EndSelect $rsoSPResults = 0 $rsoSPResults = $oSQLConn.Execute("EXEC spTableParameterPassTest " & $rsoFacFriendly) Select Case $rsoSPResults.EOF = False MsgBox(0, "sp exec2", "not end of file") $aSPResults = $rsoSPResults.GetRows() _ArrayDisplay($aSPResults) Case IsObj($rsoSPResults) = 0 MsgBox(0, "sp exec2", "rso isn't even an object") Case $rsoSPResults.EOF = True MsgBox(0, "sp exec2", "At end of file") Case Else MsgBox(0, "sp exec2", "Something else happened") EndSelect $rsoSPResults = 0 $rsoFacFriendly = 0 $oSQLConn.Close $oSQLConn = 0 Exit  
    • Swatcat
      By Swatcat
      Hi All,
      So I need Help.
      I am developing code to handle Authentication Popup For IE. The issue I am facing is that this code runs smoothly on unlock desktop but fails on VM machine and when machine is locked. So could you suggest what should I do to make it work. My automation Tool is a Selenium Based tool and is able to launch the script, but the AutoIT Script is unable to pass the username and password on the authentication popup.
      Below is the code.
      I am passing the values through Command line arguments.
      #include <Array.au3> Local $browser, $BAuthMode, $BWinAuthUserName, $BWinAuthPassword, $BChromeClaimsURL, $BChromePolicyURL, $BIEPolicyURL, $BIEClaimsURL; $browser = $CMDLine[1] $BAuthMode = $CMDLine[2] $BWinAuthUserName = $CMDLine[3] $BWinAuthPassword = $CMDLine[4] $BChromeClaimsURL = "" $BChromePolicyURL = "" $BIEURL = "" ;$BIEClaimsURL = "" If $browser = "chrome" And $BAuthMode = "m" Then If WinExists($BChromeClaimsURL,"") Then WinWaitActive($BChromeClaimsURL) ; set control to the window for proxy authentication Sleep(500) Send("{ESCAPE}") ElseIf WinExists($BChromePolicyURL,"") Then WinWaitActive($BChromePolicyURL) ; set control to the window for proxy authentication Sleep(500) Send("{ESCAPE}") EndIf ElseIf $browser = "ie" And $BAuthMode = "m" Then If WinExists($BIEPolicyURL,"") Then WinExists($BIEPolicyURL) ; set control to the window for proxy authentication Sleep(500) Send("{ESCAPE}") ElseIf WinExists($BIEClaimsURL,"") Then WinWaitActive($BIEClaimsURL) ; set control to the window for proxy authentication Sleep(500) Send("{ESCAPE}") EndIf ElseIf $browser = "ie" And $BAuthMode = "w" Then WinWaitActive($BIEURL,"","20") if(WinExists($BIEURL)) Then Sleep(500) Send($BWinAuthUserName & "{TAB}") ; send username and press TAB Sleep(100) Send($BWinAuthPassword & "{ENTER}") ; send the password and press enter Sleep(100) EndIf ElseIf $browser = "chrome" And $BAuthMode = "w" Then If WinExists($BChromeClaimsURL,"") Then WinWaitActive($BChromeClaimsURL) ; set control to the window for proxy authentication Sleep(500) Send($BWinAuthUserName & "{TAB}") ; send username and press TAB Send($BWinAuthPassword & "{ENTER}") ; send the password and press enter ElseIf WinExists($BChromePolicyURL,"") Then WinWaitActive($BChromePolicyURL) ; set control to the window for proxy authentication Sleep(500) Send($BWinAuthUserName & "{TAB}") ; send username and press TAB Send($BWinAuthPassword & "{ENTER}") ; send the password and press enter EndIf EndIf WinSetState("[ACTIVE]", "", @SW_RESTORE) Sleep(500) WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)  
       
       
       
    • Gowrisankar
      By Gowrisankar
      Dear members of the forum,
      I'm new to AutoIt and I'm having a good time exploring and enjoying the features of AutoIt.
      For one of my tasks, I've to open few particular mails from outlook based on subject of the mails and then print the mails. Can someone please guide me how to do it?
      My question could be very silly for experts. But I'm just a beginner. Kindly advice.
      Thanks and regards,
      Gowrisankar R.
    • Valnurat
      By Valnurat
      I have a
      Global $aResult[0][2] For $i = 0 to UBound($aNames) -1 Local $aUserInfo = _AD_GetObjectsInOU($aNames[$i],"","","displayName,distinguishedName") _ArrayDisplay($aUserInfo) _ArrayConcatenate($aResult, $aUserInfo, 1) _ArrayDisplay($aResult, 'AD ' & UBound($aResult)) Next I do receive empty info that's added to my array.
      How can I delete empty records?
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I'd like to know if someone else here has already tried to use an AutoIt script which work on the same DB ( i.e. SQLite ) on different Computers.
      If yes, please answer here, because I'd like to develop it, and I don't know where to start ( i.e. , I don't know how the script would work if 2 or more users are writing/reading in the same moment... )  
      Thanks!