How to provide a gui interface for modify a row's text in a ListView Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
songdg
Posts: 606
Joined: 04 Oct 2017, 20:04

How to provide a gui interface for modify a row's text in a ListView

30 Apr 2024, 05:09

How to provide a gui interface for modify a row's text in a ListView, or even it is possible if doubleclick the row will become editable :?:
User avatar
boiler
Posts: 17192
Joined: 21 Dec 2014, 02:44

Re: How to provide a gui interface for modify a row's text in a ListView

30 Apr 2024, 05:35

You could have the event for a double-click go to a function that opens a separate small GUI on top of the main one that is nothing but an Edit control and maybe OK and Cancel buttons. Its initial contents are whatever the ListView cell contained. Then when the user hits Enter or clicks an OK button on that GUI, it goes away and the ListView cell is updated with the edited contents of the popup GUI’s Edit control.

Alternatively, the Edit control doesn’t need to be in a separate GUI but could be on the same GUI above or below the ListView.
XMCQCX
Posts: 249
Joined: 14 Oct 2020, 23:44

Re: How to provide a gui interface for modify a row's text in a ListView

30 Apr 2024, 14:28

An example. Modifications can be made via double-clicking or the right-click context menu.

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance

gMain := Gui(, 'gMainTitle')
gMain.OnEvent('Close', (*) => ExitApp())
gMain.lv := gMain.Add('ListView', 'Grid Sort', ['Col1', 'Col2'])
gMain.lv.OnEvent('ContextMenu', gMain_lv_ContextMenu)
gMain.lv.OnEvent('DoubleClick', gMain_lv_DoubleClick)

loop 3
    gMain.lv.Add(, 'row' A_Index '_valueCol1', 'row' A_Index '_valueCol2')
    
loop 2
    gMain.lv.ModifyCol(A_Index, 'AutoHdr')

;==============================================

gEdit := Gui(, 'gEditTitle')
gEdit.edit_col1 := gEdit.Add('Edit')
gEdit.edit_col2 := gEdit.Add('Edit')
gEdit.btn_Ok := gEdit.Add('Button', 'Default', 'Ok')
gEdit.btn_ok.OnEvent('Click', gEdit_btn_ok_Click)
gEdit.btn_Cancel := gEdit.Add('Button',, 'Cancel')
gEdit.btn_Cancel.OnEvent('Click', gEdit_Close)
gEdit.OnEvent('Close', gEdit_Close)

gMain.Show()

;==============================================

gMain_lv_ContextMenu(ctrlObj, item, isRightClick, x, y)
{
    MouseGetPos(,,, &mouseOverClassNN)
    if item = 0 || InStr(mouseOverClassNN, 'SysHeader')
        return
    
    ctxMenu := Menu()
    ctxMenu.Add('Edit', gEdit_Show.Bind(item))
    ctxMenu.Show(x, y)
}

;==============================================

gMain_lv_DoubleClick(ctrlObj, item, *)
{
    if item = 0
        return

    gEdit_Show(item)
}

;==============================================

gEdit_btn_ok_Click(*)
{
    gMain.lv.Modify(gMain.lv_rowSelected,, gEdit.edit_col1.Value, gEdit.edit_col2.Value)

    loop 2
        gMain.lv.ModifyCol(A_Index, 'AutoHdr')

    gEdit_Close()
}

;==============================================

gEdit_Show(item, *)
{
    gMain.Opt('+Disabled')
    gEdit.Opt('+Owner' gMain.hwnd)

    gEdit.edit_col1.Value := gMain.lv.GetText(item, 1)
    gEdit.edit_col2.Value := gMain.lv.GetText(item, 2)
    gMain.lv_rowSelected := item
    gEdit.Show()
}

;==============================================

gEdit_Close(*)
{
    gMain.Opt('-Disabled') 
    gEdit.Hide()
}
XMCQCX
Posts: 249
Joined: 14 Oct 2020, 23:44

Re: How to provide a gui interface for modify a row's text in a ListView  Topic is solved

30 Apr 2024, 15:31

There is also this script by just me.
LVICE_XXS - LV in-cell editing minimal version
viewtopic.php?f=83&t=94046
songdg
Posts: 606
Joined: 04 Oct 2017, 20:04

Re: How to provide a gui interface for modify a row's text in a ListView

01 May 2024, 02:18

boiler wrote:
30 Apr 2024, 05:35
You could have the event for a double-click go to a function that opens a separate small GUI on top of the main one that is nothing but an Edit control and maybe OK and Cancel buttons. Its initial contents are whatever the ListView cell contained. Then when the user hits Enter or clicks an OK button on that GUI, it goes away and the ListView cell is updated with the edited contents of the popup GUI’s Edit control.

Alternatively, the Edit control doesn’t need to be in a separate GUI but could be on the same GUI above or below the ListView.
Thanks for the detailed guidance :clap:
songdg
Posts: 606
Joined: 04 Oct 2017, 20:04

Re: How to provide a gui interface for modify a row's text in a ListView

01 May 2024, 02:19

XMCQCX wrote:
30 Apr 2024, 14:28
An example. Modifications can be made via double-clicking or the right-click context menu.

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance

gMain := Gui(, 'gMainTitle')
gMain.OnEvent('Close', (*) => ExitApp())
gMain.lv := gMain.Add('ListView', 'Grid Sort', ['Col1', 'Col2'])
gMain.lv.OnEvent('ContextMenu', gMain_lv_ContextMenu)
gMain.lv.OnEvent('DoubleClick', gMain_lv_DoubleClick)

loop 3
    gMain.lv.Add(, 'row' A_Index '_valueCol1', 'row' A_Index '_valueCol2')
    
loop 2
    gMain.lv.ModifyCol(A_Index, 'AutoHdr')

;==============================================

gEdit := Gui(, 'gEditTitle')
gEdit.edit_col1 := gEdit.Add('Edit')
gEdit.edit_col2 := gEdit.Add('Edit')
gEdit.btn_Ok := gEdit.Add('Button', 'Default', 'Ok')
gEdit.btn_ok.OnEvent('Click', gEdit_btn_ok_Click)
gEdit.btn_Cancel := gEdit.Add('Button',, 'Cancel')
gEdit.btn_Cancel.OnEvent('Click', gEdit_Close)
gEdit.OnEvent('Close', gEdit_Close)

gMain.Show()

;==============================================

gMain_lv_ContextMenu(ctrlObj, item, isRightClick, x, y)
{
    MouseGetPos(,,, &mouseOverClassNN)
    if item = 0 || InStr(mouseOverClassNN, 'SysHeader')
        return
    
    ctxMenu := Menu()
    ctxMenu.Add('Edit', gEdit_Show.Bind(item))
    ctxMenu.Show(x, y)
}

;==============================================

gMain_lv_DoubleClick(ctrlObj, item, *)
{
    if item = 0
        return

    gEdit_Show(item)
}

;==============================================

gEdit_btn_ok_Click(*)
{
    gMain.lv.Modify(gMain.lv_rowSelected,, gEdit.edit_col1.Value, gEdit.edit_col2.Value)

    loop 2
        gMain.lv.ModifyCol(A_Index, 'AutoHdr')

    gEdit_Close()
}

;==============================================

gEdit_Show(item, *)
{
    gMain.Opt('+Disabled')
    gEdit.Opt('+Owner' gMain.hwnd)

    gEdit.edit_col1.Value := gMain.lv.GetText(item, 1)
    gEdit.edit_col2.Value := gMain.lv.GetText(item, 2)
    gMain.lv_rowSelected := item
    gEdit.Show()
}

;==============================================

gEdit_Close(*)
{
    gMain.Opt('-Disabled') 
    gEdit.Hide()
}
Thanks for providing the example :dance:
songdg
Posts: 606
Joined: 04 Oct 2017, 20:04

Re: How to provide a gui interface for modify a row's text in a ListView

01 May 2024, 02:22

XMCQCX wrote:
30 Apr 2024, 15:31
There is also this script by just me.
LVICE_XXS - LV in-cell editing minimal version
viewtopic.php?f=83&t=94046
Thanks for sharing the code, "in-cell editing" that's really amazing. :bravo:

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: mikeyww and 61 guests