Jump to content

_GUICtrlListViewFindItem Issues


Recommended Posts

Hi Folks,

I have a listview consisting of a few columns:

|Alert ID|Device Type|Duration|Last Change|Device Name|Event Updated|Status

The first column is - or should be - a checkbox.

Anyhow, its filled with multiple items, but when searching it gives me an error.

I tried modifying the code in the manual, so it would look a bit like my program but that also gives the same problem.

I can't seem to pinpoint the exact cause, tried multiple things.

The only result i get back is when i use something in the first column (column 0 right?) but not in the 2nd column (column 1).

This is the code i ended up with:

#include <GuiConstants.au3>
#include <GuiListView.au3>

Opt('MustDeclareVars', 1)
Dim $listview, $Btn_FindExact, $Btn_FindPartial, $Btn_FindByID, $Btn_Exit, $msg, $ret, $input_find, $index, $item[5]
GUICreate("ListView Find Item", 392, 322)

$listview = GUICtrlCreateListView("Test|Alert ID|Device Type|Duration|Last Change|Device Name|Event Updated|Status", 40, 30, 310, 149, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
$item[0] = GUICtrlCreateListViewItem("Y|1337|PC1|0d 1h|13-12-2000 13:25:55|Blaatjes1|Haha1|Status1", $listview)
$item[1] = GUICtrlCreateListViewItem("Y|1338|PC2|0d 2h|14-12-2000 14:25:55|Blaatjes2|Haha2|Status2", $listview)
$item[2] = GUICtrlCreateListViewItem("C|1339|PC3|0d 3h|15-12-2000 15:25:55|Blaatjes3|Haha3|Status3", $listview)
$item[3] = GUICtrlCreateListViewItem("N|1340|PC4|0d 4h|16-12-2000 16:25:55|Blaatjes4|Haha4|Status4", $listview)
$item[4] = GUICtrlCreateListViewItem("N|1341|PC5|0d 5h|17-12-2000 17:25:55|Blaatjes5|Haha5|Status5", $listview)

GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($listview, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
;~ _GUICtrlListViewSetColumnWidth($listview, 0, 100)
$input_find = GUICtrlCreateInput("", 40, 200, 200, 20)
$Btn_FindPartial = GUICtrlCreateButton("Find (Partial)", 40, 230, 90, 30)
$Btn_FindExact = GUICtrlCreateButton("Find (Exact)", 145, 230, 90, 30)
$Btn_FindByID = GUICtrlCreateButton("Find by ID", 95, 270, 90, 30)
$Btn_Exit = GUICtrlCreateButton("Exit", 300, 260, 70, 30)

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
            ExitLoop
        Case $msg = $Btn_FindPartial
            $index = _GUICtrlListViewFindItem ($listview, GUICtrlRead($input_find), -1, BitOR($LVFI_PARTIAL, $LVFI_WRAP))
            If $index = $LV_ERR Then
                MsgBox(0, "Find Partial", "Error")
            Else
                MsgBox(0, "Find Partial", "Index: " & $index)
            EndIf
        Case $msg = $Btn_FindExact
            $index = _GUICtrlListViewFindItem ($listview, GUICtrlRead($input_find), -1, BitOR($LVFI_STRING, $LVFI_WRAP))
            If $index = $LV_ERR Then
                MsgBox(0, "Find Exact", "Error")
            Else
                MsgBox(0, "Find Exact", "Index: " & $index)
            EndIf
        Case $msg = $Btn_FindByID
            $index = _GUICtrlListViewFindItem ($listview, GUICtrlRead($input_find), -1, BitOR($LVFI_PARAM, $LVFI_WRAP))
            If $index = $LV_ERR Then
                MsgBox(0, "Find by ID", "Error")
            Else
                MsgBox(0, "Find by ID", "Index: " & $index)
            EndIf
    EndSelect
WEnd
Exit

Also tried using "$VK_RIGHT"..

Maybe someone sees the problem :whistle: Always better to use some fresh eyes, right?

Edited by Sypher
Link to comment
Share on other sites

I also tried using A3LListview but it seems that it can only find the first column as well:

#include <A3LListView.au3>
#include <GUIConstants.au3>
#include <GUIListView.au3>

Global $hGUI, $iList, $iBtn, $hList, $iIndex, $iMsg

$hGUI  = GUICreate("Test", 400, 300)
$iList = GUICtrlCreateListView("CB|Alert ID|Device Type|Duration|Last Change|Device Name|Event Updated|Status", 2, 2, 396, 260, -1, $LVS_EX_CHECKBOXES)
$iBtn  = GUICtrlCreateButton("OK", 165, 270, 75, 25)
_GUICtrlListViewSetColumnWidth($iList, 0, 317)
$hList = GUICtrlGetHandle($iList)
GUISetState()

_GUICtrlListViewInsertItem($iList, 0, "ABC|DEF|AB|!!|DD|EE|FF")
_GUICtrlListViewInsertItem($iList, 1, "GHI|JKL|BA|??|GG|HH|II")
_GUICtrlListViewInsertItem($iList, 2, "11|22|33|44|55|66|77")
_GUICtrlListViewInsertItem($iList, 3, "111|222|333|444|555|666|777")

While 1
  $iMsg = GUIGetMsg()
  Switch $iMsg
    Case $iBtn
      $iIndex = _ListView_FindText($hList, "JKL")
      MsgBox(0,"",$iIndex)
    Case $GUI_EVENT_CLOSE
      Exit
  EndSwitch
WEnd

Can someone Please help me out with this?

Edited by Sypher
Link to comment
Share on other sites

I also tried using A3LListview but it seems that it can only find the first column as well:

The problem is you're not using the correct function.

#include <A3LListView.au3>

Global $hGUI, $hList, $iBtn, $iIndex

$hGUI  = GUICreate("Test", 400, 300)
$hList = _ListView_Create($hGUI, 2, 2, 396, 260)
$iBtn  = GUICtrlCreateButton("OK", 165, 270, 75, 25)
_ListView_SetExtendedListViewStyle($hList, $LVS_EX_CHECKBOXES)
GUISetState()

_ListView_InsertColumn($hList, 0, "CB"           )
_ListView_InsertColumn($hList, 1, "Alert ID"     )
_ListView_InsertColumn($hList, 2, "Device Type"  )
_ListView_InsertColumn($hList, 3, "Duration"     )
_ListView_InsertColumn($hList, 4, "Last Change"  )
_ListView_InsertColumn($hList, 5, "Device Name"  )
_ListView_InsertColumn($hList, 6, "Event Updated")
_ListView_InsertColumn($hList, 7, "Status"       )

_ListView_AddItem   ($hList, 0, "ABC")
_ListView_AddSubItem($hList, 0, "DEF", 1)
_ListView_AddSubItem($hList, 0, "AB" , 2)
_ListView_AddSubItem($hList, 0, "!!" , 3)
_ListView_AddSubItem($hList, 0, "DD" , 4)
_ListView_AddSubItem($hList, 0, "EE" , 5)
_ListView_AddSubItem($hList, 0, "FF" , 6)

while 1
  Switch GUIGetMsg()
    case $iBtn
      $iIndex = _ListView_FindInText($hList, "DD")
      MsgBox(0, "", $iIndex)
    case $GUI_EVENT_CLOSE
      Exit
  EndSwitch
wend
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

Okay, i couldn't really find anything usefull concerning either "_ListView_FindInText" nor "_GuiCtrlListViewFindItem".

Anyhow, i "fixed" it by merging the first two columns. Now it's still working, but with GCLVFI not LVFIT.

Either way, thanks!

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