Jump to content

Edit ListView items - Like it should be ?


AcidUser
 Share

Recommended Posts

Hello Everyone!

I'm working on Multi-line Editable, Draggable ListView GUI.

For the first task I found a good example of multi-line editable GUI here:

This example is really good, but the problem is that this "Edit Listview item" is not very user-friendly.

If I double-click on item - it does enable EDIT mode - that is OK.

The third click on this editable cell - Disables EDIT mode - that is a no-no.

Because everywhere when you edit string (file name in windows or whatever) - when item is selected for EDIT on the next click - active Cursor moves to the point where you clicked (item is still in EDIT mode) - AND you also have opportunity to select a part of text with mouse.

Is it possible to implement in Autoit?

Some directions and advises from experienced AutoIt users may help a lot.

Thank you in advance.

Link to comment
Share on other sites

Looking at that code, it is not an easy way of editing a cell. I see what you mean that it is annoying that on the third click, it disables the editing ability. I think the biggest problem (at least for me) is since the cell is highlighted in blue, you have this need to un-highlight the selected text, so you feel like you have to click to deselect the text (like it works in most applications).

My suggestion below does not fix your problem. It only un-selects the text and reduces your urge to click a third time. I added sending a right arrow on line 67.

#include <GuiConstants.au3>
#include <GuiEdit.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

Opt("GuiCloseOnESC", 0)

Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0

Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)

$hGUI = GUICreate("ListView Subitems edit in place", 300, 200)

$hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems", 2, 2, 296, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES)

For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, "Item " & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR, $hWndFrom, $iCode

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_DBLCLK
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)

                    If ($aHit[0] <> -1) And ($aHit[1] = 0) Then
                        $Item = $aHit[0]
                        $SubItem = 0
                        Local $aRect = _GUICtrlListView_GetItemRect($hListView, $Item)
                    ElseIf ($aHit[0] <> -1) And ($aHit[1] > 0) Then
                        $Item = $aHit[0]
                        $SubItem = $aHit[1]
                        Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem)
                    Else
                        Return $GUI_RUNDEFMSG
                    EndIf

                    Local $iItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
                    Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iItemText)
                    $hEdit = _GUICtrlEdit_Create($hGUI, $iItemText, $aRect[0] + 3, $aRect[1], $iLen + 10, 17, $Style)

                    _GUICtrlEdit_SetSel($hEdit, 0, -1)
                    _WinAPI_SetFocus($hEdit)
                    $hDC = _WinAPI_GetWindowDC($hEdit)
                    $hBrush = _WinAPI_CreateSolidBrush(0x0000FF)
                    FrameRect($hDC, 0, 0, $iLen + 10 , 17, $hBrush)
                    Send("{Right}")
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
    Local $stRect = DllStructCreate("int;int;int;int")

    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)

    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iCode = BitShift($wParam, 16)

    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    Local $iText = _GUICtrlEdit_GetText($hEdit)
                    _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
                    _WinAPI_DeleteObject($hBrush)
                    _WinAPI_ReleaseDC($hEdit, $hDC)
                    _WinAPI_DestroyWindow($hEdit)

                    $Item = -1
                    $SubItem = 0
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

#include <ByteMe.au3>

Link to comment
Share on other sites

For editing all subitems of listview I like the best this example

Thank you! this is exactly what I was looking for. :D

Now I'm working on file filter: *.msi, *.exe, *.reg

then will try to make them draggable in a list using mouse.

I'll share code if it works

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