Sign in to follow this  
Followers 0
Mingre

[SOLVED] Removing selection in a listview after losing focus

2 posts in this topic

#1 ·  Posted (edited)

Hello again AutoIt Forums,

In the sample script below, the GUI has 3 listviews. What lines do I need to add so that the previous selection on a listview will be cancelled after I selected an item on another listview?

Thanks!

#include <Array.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <File.au3>
#include <ListviewConstants.au3>
#include <SendMessage.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $iIndex = -1, $iSubIndex = -1, $no = 3, $_Files[$no], $asFiles[$no], $hGUI_ListView[$no], $hListView[$no], $hGUI_ListView_ImageList[$no]

Global $sFolderPath[$no] = [@DesktopDir, 'C:', 'D:']
$hGUI = GUICreate('GUI', 750, @DesktopHeight / 2)
For $a = 0 To $no - 1 Step +1
$asFiles = _FileListToArray($sFolderPath[$a])
$_size = UBound($asFiles)
If Not IsDeclared('_Compare') Then
  Dim $_Files[$no][$_size]
  Local $_Compare = $_size
Else
  If $_size > $_Compare Then ReDim $_Files[$no][$_size]
EndIf
$hGUI_ListView[$a] = GUICtrlCreateListView($a, $a * 250, 0, 250, @DesktopHeight / 2)
$hListView[$a] = GUICtrlGetHandle($hGUI_ListView[$a])

For $i = 1 To $asFiles[0]
  $lvitem = GUICtrlCreateListViewItem($asFiles[$i], $hGUI_ListView[$a])
Next
Next
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   _exit()
EndSwitch
WEnd
#region - Functions
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
For $c = 0 To $no - 1 Step +1
  If $hWndFrom = $hListView[$c] Then
   If $iCode = $NM_DBLCLK Then
    _dblclk($c)
   ElseIf $iCode = $NM_KILLFOCUS Then
    ConsoleWrite(@CRLF & 'killfocus from ' & $c & @CRLF)
    ; What do I need to insert here?
   EndIf
  EndIf
Next
Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Func _dblclk($no)
Local $aHit = _GUICtrlListView_SubItemHitTest($hListView[$no])
If ($aHit[0] <> -1) And (($aHit[0] <> $iIndex) Or ($aHit[1] <> $iSubIndex)) Then
  $_filename = $sFolderPath[$no] & '\' & $_Files[$no][$aHit[0] + 1]
  ConsoleWrite(@CRLF & 'Double click ' & @CRLF & $_filename & @CRLF)
EndIf
EndFunc   ;==>_execute
Func _exit()
Exit
EndFunc   ;==>_exit
#endregion - Functions
Edited by Lilbert

Share this post


Link to post
Share on other sites



Hello,

Just found out about ControlListView().

Problem solved. Thanks guys!

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