Item editor modal

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
laulau
Posts: 35
Joined: 06 Nov 2020, 16:53

Item editor modal

29 Nov 2020, 05:25

What would be a typical ahk way to do a edit form function for an item list? I've managed to do gui that lists a set of items with texts. Each item has an edit button and I want the textbox to be editable when edit is clicked. So it would need to change into an edit text control with an OK and cancel buttons. I guess it could be an additional modal gui or it could be in the original gui.

Are there any best practices or tutorials for this?
User avatar
mikeyww
Posts: 26952
Joined: 09 Sep 2014, 18:38

Re: Item editor modal

29 Nov 2020, 08:17

At least two ways:

1. Controls can be disabled or set to read-only, so you could create toggles as you wish.

2. Listview also has its own read-only feature, and can accommodate a column of checkboxes.

Both are explained in the documentation.
laulau
Posts: 35
Joined: 06 Nov 2020, 16:53

Re: Item editor modal

29 Nov 2020, 09:11

mikeyww wrote:
29 Nov 2020, 08:17
At least two ways:

1. Controls can be disabled or set to read-only, so you could create toggles as you wish.
Is there any easy way to group controls?
User avatar
mikeyww
Posts: 26952
Joined: 09 Sep 2014, 18:38

Re: Item editor modal

29 Nov 2020, 09:52

You could give your groups similar names, so that, for example, if you click on checkbox1, it enables edit1, checkbox2 enables edit2, and so on.
laulau
Posts: 35
Joined: 06 Nov 2020, 16:53

Re: Item editor modal

29 Nov 2020, 10:31

mikeyww wrote:
29 Nov 2020, 09:52
You could give your groups similar names, so that, for example, if you click on checkbox1, it enables edit1, checkbox2 enables edit2, and so on.
And parse the controller name for the nr to target the other controls with the same nr?
User avatar
mikeyww
Posts: 26952
Joined: 09 Sep 2014, 18:38

Re: Item editor modal

29 Nov 2020, 10:36

That is fine, too.
laulau
Posts: 35
Joined: 06 Nov 2020, 16:53

Re: Item editor modal

29 Nov 2020, 13:43

Hmmm I don't get it. If I have an unknown amount of items how could I set it up so that BtnEditX will show EditTextX and OkButtonX without knowing their number?
User avatar
mikeyww
Posts: 26952
Joined: 09 Sep 2014, 18:38

Re: Item editor modal

29 Nov 2020, 14:32

When you add a "row" or group, you can increment an item counter that then uses that counter in each of the variables or control names. You could try it with two or three groups to see how it works.
laulau
Posts: 35
Joined: 06 Nov 2020, 16:53

Re: Item editor modal

29 Nov 2020, 14:53

mikeyww wrote:
29 Nov 2020, 14:32
When you add a "row" or group, you can increment an item counter that then uses that counter in each of the variables or control names. You could try it with two or three groups to see how it works.
Would each row than have its own button handler that toggles the controls of that row?
User avatar
mikeyww
Posts: 26952
Joined: 09 Sep 2014, 18:38

Re: Item editor modal

29 Nov 2020, 14:56

Yes, as that is what I imagined you wanted, from your description.
Each item has an edit button and I want the textbox to be editable when edit is clicked. So it would need to change into an edit text control with an OK and cancel buttons.

Code: Select all

Gui, Font, s10
Gui, Add, Checkbox, vcheck1 gToggle
Gui, Add, Edit, x+m vedit1 w100
Gui, Show, w190, Test
editToggle("edit1")
Return

Toggle:
editToggle(StrReplace(A_GuiControl, "check", "edit"))
Return

GuiEscape:
GuiClose:
ExitApp

editToggle(control) {
 GuiControlGet, enabled, Enabled, %control%
 GuiControl, % (enabled ? "Disable" : "Enable"), %control%
 GuiControl, Focus, %control%
}
laulau
Posts: 35
Joined: 06 Nov 2020, 16:53

Re: Item editor modal

29 Nov 2020, 15:08

mikeyww wrote:
29 Nov 2020, 14:56
Yes, as that is what I imagined you wanted, from your description.
Each item has an edit button and I want the textbox to be editable when edit is clicked. So it would need to change into an edit text control with an OK and cancel buttons.
Yes exactly. OK I get it. So when I declare a label for a handler I can use variables in its name as well?
Like
ItemEditButtonClicked%index%:
;OnClick logic here
User avatar
mikeyww
Posts: 26952
Joined: 09 Sep 2014, 18:38

Re: Item editor modal

29 Nov 2020, 15:16

Sure.

Code: Select all

Gui, Font, s10
Loop, 2 {
 Gui, Add, Checkbox, xm vcheck%A_Index% gToggle
 Gui, Add, Edit, x+m vedit%A_Index% w100
 editToggle("edit" A_Index)
}
Gui, Show, w190, Test
Return

Toggle:
editToggle(StrReplace(A_GuiControl, "check", "edit"))
Return

GuiEscape:
GuiClose:
ExitApp

editToggle(control) {
 GuiControlGet, enabled, Enabled, %control%
 GuiControl, % (enabled ? "Disable" : "Enable"), %control%
 GuiControl, Focus, %control%
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, haomingchen1998, mikeyww, Oblomov228, RussF and 274 guests