Sign in to follow this  
Followers 0
Melba23

ListView Highlighting Problems

3 posts in this topic

#1 ·  Posted (edited)

Hi,

I am running into a problem with ListView - I cannot get the highlight working correctly. The example code showing the problem (at least it does on my Vista32 machine) is here:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <File.au3>
#include <GUIListView.au3>
#Include <GuiEdit.au3>

Global $aArray[10] = ["1=Punc", "2=abc", "3=def", "4=ghi", "5=jkl", _
                      "6=mno", "7=pqrs", "8=tuv", "9=wxyz", "0=Space"]
Global $iIndex = 0

$hMain_Window = GUICreate("List View Example", 240, 300, -1, -1)

$hSearch_Input = GUICtrlCreateInput("", 15, 15, 90, 20)

$hSearch_Button = GUICtrlCreateButton("Search", 125, 10, 80, 30, $BS_DEFPUSHBUTTON)

$hList_View = GUICtrlCreateListView("Item1|Item2", 15, 50, 210, 245)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)
GUICtrlSetBkColor(-1, 0xFF0000)
_GUICtrlListView_SetColumnWidth(-1, 0, 90)
_GUICtrlListView_SetColumnWidth(-1, 1, $LVSCW_AUTOSIZE_USEHEADER)

_LV_Fill()

GUISetState(@SW_SHOW, $hMain_Window)

GUIRegisterMsg($WM_NOTIFY, "MY_WM_COMMAND")

While 1
    
    $iMsg = GUIGetMsg()
    
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hSearch_Button
            _Search()
    EndSwitch

WEnd


Func _Search()
;_GUICtrlListView_SetItemSelected($hList_View, $iIndex, False)
    $sTxt = GUICtrlRead($hSearch_Input)
    If $sTxt = "" Then Return
    $iIndex = _FindItem($hList_View, $sTxt, 0)
    If $iIndex = -1 Then
        MsgBox(0, "Search Error", "The element " & $sTxt & " does not exist.")
    Else
        _GUICtrlListView_SetItemSelected($hList_View, $iIndex)
        _GUICtrlListView_EnsureVisible($hList_View, $iIndex)
    EndIf
EndFunc

Func _LV_Fill()

    For $i = 0 To UBound($aArray) - 1
        $aVar = _Split($aArray[$i], "=")
        GUICtrlCreateListViewItem($aVar[0] & "|" & $aVar[1], $hList_View)
        GUICtrlSetBkColor(-1, 0x00FF00)
    Next
    
EndFunc

Func _FindItem($hWnd, $2Find, $SubIndex)
    Local $iOut = -1
    For $i = 0 To _GUICtrlListView_GetItemCount($hWnd) - 1
        If _GUICtrlListView_GetItemText($hWnd, $i, $SubIndex) = $2Find Then $iOut = $i
    Next
    Return $iOut
EndFunc

Func _Split($sString, $sDelim)
    Local $aOut[2]
    Local $iLen = StringLen($sString)
    Local $iPos = StringInStr($sString, $sDelim, 1, 1)
    $aOut[0] = StringLeft($sString, $iPos - 1)
    $aOut[1] = StringRight($sString, $iLen - $iPos)
    Return $aOut
EndFunc

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $tagNMHDR, $vEvent
    Switch $wParam
        Case $hList_View
            $tagNMHDR = DllStructCreate("int;int;int", $lParam)
            If @error Then Return
            $vEvent = DllStructGetData($tagNMHDR, 3)
            Switch $vEvent
                Case $NM_CLICK
                    GUICtrlSetData($hSearch_Input, _GUICtrlListView_GetItemText($hList_View, _GUICtrlListView_GetHotItem($hList_View), 0))
            EndSwitch
    EndSwitch
    $tagNMHDR = 0
EndFunc
Edited by Melba23

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



@Ichigo,

Gracias.

I just knew it was something simple!

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

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
Sign in to follow this  
Followers 0