Jump to content
Sign in to follow this  
buymeapc

Editable ListView On Tab - Odd Behavior

Recommended Posts

buymeapc

Hi all,

So I've come across a stange GUI issue when I have an editable listview on a tab. When I double-click an item on the listview, the hidden edit window appears, but in order to see it and the outlines of the input box, I have to move the mouse cursor away.

How can I make it so that when I double-click on the item, the input box is displayed without having to move the mouse cursor?

I borrowed a bit of code from this example - great code:

Here's a quick reproducer to see what I'm talking about

#include <GuiTab.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $iWidth = 700, $iHeight = 430, $sTitle = "Test"
Global $hInput, $hListView, $aElement[2]

_Main()
Func _Main()
$hGUI = GUICreate("Test", $iWidth, $iHeight)
$dummy1 = GUICtrlCreateDummy()
$dummy2 = GUICtrlCreateDummy()
Global $AccelKeys[2][2] = [["{ESC}", $dummy1],["{ENTER}", $dummy2]]
     GUISetAccelerators($AccelKeys)
$hTab = GUICtrlCreateTab(0, 0, 700, 407, $TCS_FIXEDWIDTH)
_GUICtrlTab_SetItemSize($hTab, 348, 18)
$hTab1 = GUICtrlCreateTabItem("Tab1")
$listView = GUICtrlCreateListView("Parameter|Value|Type", 250, 22, 448, 268, $LVS_SINGLESEL+$LVS_SHOWSELALWAYS)
$hListView = GUICtrlGetHandle($listView)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES, $LVS_EX_INFOTIP, $LVS_REPORT, $LVS_EX_FULLROWSELECT))
_GUICtrlListView_SetColumnWidth($hListView, 0, 150)
_GUICtrlListView_SetColumnWidth($hListView, 1, 230)
_GUICtrlListView_SetColumnWidth($hListView, 2, $LVSCW_AUTOSIZE_USEHEADER)
GUICtrlCreateListViewItem("item1|item2|item3", $listView)
$hInput = GUICtrlCreateInput("", 0, 0, 0, 0, 0x280)
     GUICtrlSetState($hInput, $GUI_HIDE)
$hTab2 = GUICtrlCreateTabItem("Tab2")
GUICtrlCreateTabItem("") ; end tabitem definition
GUISetState(@SW_SHOW, $hGUI)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
Sleep(10)
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then Exit
If $msg = $dummy1 Then _NoSave()
If $msg = $dummy2 Then _SaveChange()
WEnd
EndFunc
Func _NoSave()
GUICtrlSetState($hInput, $GUI_HIDE)
EndFunc ;==>_NoSave
Func _SaveChange()
Local $aWork, $x, $sText, $data, $aSplit, $string = ""
If GUICtrlGetState($hInput) <> 80 Then Return; 80 = shown / 96 = hidden (we don't want the user just pressing ENTER without the input field visible)
Local $sText = GUICtrlRead($hInput)
_GUICtrlListView_SetItemText($hListView, $aElement[0], $sText, $aElement[1])
GUICtrlSetState($hInput, $GUI_HIDE)
EndFunc
Func _GUICtrlListView_EditItem($hWnd, $iIndex, $iSubItem)
;funkey 19.02.2010
If $iIndex < 0 Then Return
If $iSubItem <> 1 Then Return; If the subitem clicked is not 1, then just return - no editing done
Local $aPos, $aRect, $iSum = 0
Local $x, $y, $w, $h
For $i = 0 To $iSubItem - 1
$iSum += _GUICtrlListView_GetColumnWidth($hWnd, $i)
Next
;GUICtrlSetBkColor(_GUICtrlListView_GetItemParam($hWnd, $iIndex), 0x0000FF)
$aRect = _GUICtrlListView_GetItemRect($hWnd, $iIndex)
$aPos = ControlGetPos($sTitle, "", $hWnd)
$x = $iSum + $aPos[0] + $aRect[0]
$y = $aPos[1] + $aRect[1]
$w = _GUICtrlListView_GetColumnWidth($hWnd, $iSubItem)
$h = $aRect[3] - $aRect[1]
GUICtrlSetPos($hInput, $x + 3, $y + 1, $w, $h + 4)
GUICtrlSetData($hInput, _GUICtrlListView_GetItemText($hWnd, $iIndex, $iSubItem))
GUICtrlSetState($hInput, $GUI_SHOW)
GUICtrlSetState($hInput, $GUI_ONTOP)
GUICtrlSetState($hInput, $GUI_FOCUS)
$aElement[0] = $iIndex
$aElement[1] = $iSubItem
EndFunc
Func WM_NOTIFY($hWnd, $nMsg, $wParam, $lParam)
Local $stNmhdr = DllStructCreate("dword;int;int", $lParam)
Local $hWndFrom = DllStructGetData($stNmhdr, 1)
Local $nNotifyCode = DllStructGetData($stNmhdr, 3)
Local $hItem = 0
$hWndListView = $hListView
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
    Case $NM_DBLCLK
     Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
     _GUICtrlListView_EditItem($hWndListView, DllStructGetData($tInfo, "Index"), DllStructGetData($tInfo, "SubItem"))
     Return $GUI_RUNDEFMSG
    Case $NM_CLICK
     GUICtrlSetState($hInput, $GUI_HIDE)
EndSwitch
EndSwitch
EndFunc

Share this post


Link to post
Share on other sites
Melba23

buymeapc,

Add this after you create the Input control: :)

GUICtrlSetPos($hInput, $x + 3, $y + 1, $w, $h + 4)
GUICtrlSetData($hInput, _GUICtrlListView_GetItemText($hWnd, $iIndex, $iSubItem))
GUICtrlSetState($hInput, $GUI_SHOW)
GUICtrlSetState($hInput, $GUI_ONTOP)
GUICtrlSetState($hInput, $GUI_FOCUS)
$aMPos = MouseGetPos()                     ; <<<<<<<<<<<<<<<<<<<<<<
MouseMove($aMPos[0], $aMpos[1] + 20, 0)    ; <<<<<<<<<<<<<<<<<<<<<<
Sleep(10)                                  ; <<<<<<<<<<<<<<<<<<<<<<
MouseMove($aMPos[0], $aMpos[1], 0)         ; <<<<<<<<<<<<<<<<<<<<<<
$aElement[0] = $iIndex
$aElement[1] = $iSubItem

It is a kludge, but it works for me - I will try and work out a better solution later. ;)

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
buymeapc

Ah, cool! That does, indeed, work. Thanks, Melba!

As an addendum, is there a way that the input field could cover the cell so the text behind isn't seen? For some reason, I can still see the text in the background. Not a biggie, but something that just bugs me :idiot:

Share this post


Link to post
Share on other sites
buymeapc

Does anyone know how to hide the text in the background using the above script?

Share this post


Link to post
Share on other sites
Melba23

buymeapc,

It does not show through for me - what theme are you using? :huh:

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
buymeapc

I'm using the default (blue) Windows XP theme.

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  

×