AndyS01 Posted October 18, 2011 Share Posted October 18, 2011 I have a listview item with 4 columns and I want to hilight the cell (row,col) that I click on. I have WM_NOTIFY code that detects the click, but I cannot get the single cell to be hilighted. It only hilights column 0 in any of the rows. here is my test code:expandcollapse popup#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Global $hMainWin, $hListView_Hwnd _Main() Func _Main() Local $flags = 0, $xflags = 0, $str, $x $hMainWin = GUICreate("Main", 450, 160) $flags = BitOR($flags, $LVS_REPORT) $flags = BitOR($flags, $LVS_SHOWSELALWAYS) $xflags = BitOR($xflags, $LVS_EX_GRIDLINES) $xflags = BitOR($xflags, $LVS_EX_DOUBLEBUFFER) $hListView_Hwnd = GUICtrlCreateListView("", 1, 1, 445, 150, $flags, $xflags) For $x = 0 To 3 _GUICtrlListView_InsertColumn($hListView_Hwnd, $x, "Col " & $x, 100) Next For $x = 0 To 9 $str = StringFormat("L%dC0|L%dC1|L%dC2|L%dC3", $x, $x, $x, $x) GUICtrlCreateListViewItem($str, $hListView_Hwnd) Next GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetOnEvent($GUI_EVENT_CLOSE, "Event_GUIClose") Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main Func WM_NOTIFY($hWnd, $msg, $wparam, $lparam) #forceref $hWnd, $Msg, $wParam, $lParam Local $tNMBHOTITEM, $nNotifyCode, $hCtrl, $selrow, $selcol, $ar $tNMBHOTITEM = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags", $lparam) $nNotifyCode = DllStructGetData($tNMBHOTITEM, "Code") $hCtrl = DllStructGetData($tNMBHOTITEM, "hWndFrom") Switch $nNotifyCode Case $NM_CLICK $ar = _GUICtrlListView_SubItemHitTest($hCtrl) $selrow = $ar[0] $selcol = $ar[1] ConsoleWrite("+++: $NM_CLICK - row " & $selrow & ", col " & $selcol & @CRLF) Case $NM_DBLCLK $ar = _GUICtrlListView_SubItemHitTest($hCtrl) $selrow = $ar[0] $selcol = $ar[1] ConsoleWrite("+++: $NM_DBLCLK - row " & $selrow & ", col " & $selcol & @CRLF) EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func Event_GUIClose() Exit (0) EndFunc ;==>Event_GUIClose Link to comment Share on other sites More sharing options...
martin Posted October 18, 2011 Share Posted October 18, 2011 Search for NM_CUSTOMDRAW and you will find examples. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 18, 2011 Moderators Share Posted October 18, 2011 AndyS01, How about this as a simple workaround - needs polishing but it proves the concept: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <Constants.au3> #Include <GuiEdit.au3> Global $iOffset_X = 10, $iOffset_Y = 1 Global $fClick = False, $hLabel $GUI = GUICreate("Test", 500, 500) $ListView = _GUICtrlListView_Create($GUI, "Col 0|Col 1", $iOffset_X, $iOffset_Y, 480, 480) For $i = 0 To 4 $iIndex = _GUICtrlListView_AddItem($ListView, "TEST" & $i) _GUICtrlListView_AddSubItem($ListView, $iIndex, "TEST1" & $i, 1) Next _GUICtrlListView_SetColumnWidth($ListView, 0, 240) _GUICtrlListView_SetColumnWidth($ListView, 1, $LVSCW_AUTOSIZE_USEHEADER) $GUIshow = GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") ; For click on ListView While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch ; If a ListView was clicked If $fClick Then $aHit = _GUICtrlListView_SubItemHitTest($ListView) If $aHit[0] <> -1 Then _HighLight() EndIf $fClick = False EndIf WEnd Func _HighLight() ; Prevent resizing of columns ControlDisable($GUI, "", HWnd(_GUICtrlListView_GetHeader($ListView))) ; Get current text $sItemOrgText = _GUICtrlListView_GetItemText($ListView, $aHit[0], $aHit[1]) ; Get size of Label Local $aRect = _GUICtrlListView_GetSubItemRect($ListView, $aHit[0], $aHit[1]) ; Delete any existing Label GUICtrlDelete($hLabel) ; Cretae a new label $hLabel = GUICtrlCreateLabel($sItemOrgText, $aRect[0] + $iOffset_X + 5, $aRect[1] + $iOffset_Y, _GUICtrlListView_GetColumnWidth($ListView, $aHit[1]) - 7, $aRect[3] - $aRect[1], Default, $WS_EX_TOPMOST) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlSetColor(-1, 0xFFFFFF) EndFunc Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Local $iCode = DllStructGetData($tNMHDR, "Code") ; Check if a ListView has sent the message If $hWndFrom = $ListView Then Switch $iCode Case $NM_CLICK ; Set flag $fClick = True EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc I hope it helps. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
AndyS01 Posted October 18, 2011 Author Share Posted October 18, 2011 That headed me in the right direction. Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now