Can the newly added item be move to the top of a listbox and selected
Can the newly added item be move to the top of a listbox and selected
I want to use GuiCtrl.Add(Items) method to add a new entry to a listbox, and move it to the top place.
Re: Can the newly added item be move to the top of a listbox and selected
Use GuiCtrl.Delete first, then add the entire list using GuiCtrl.Add() with the whole array that has the items in the order you want them (use Array.InsertAt(1) to add your new item at the top of the array). Then use GuiCtrl.Choose(1) to select the first item.
Re: Can the newly added item be move to the top of a listbox and selected
Another way using SendMessage:
Code: Select all
#Requires AutoHotkey v2.0
g := Gui()
g.AddText(, "Add a new item:")
myEdit := g.AddEdit("w150")
g.AddButton("yp", "Enter").OnEvent("Click", AddItemToListBox)
myListBox := g.AddListBox("xm r10 w200", ["apple", "orange", "banana"])
g.Show()
AddItemToListBox(*) {
LB_INSERTSTRING := 0x0181
index := 0 ; wParam is zero-indexed position to insert at
SendMessage(LB_INSERTSTRING, index, StrPtr(myEdit.Text), myListBox)
myListBox.Choose(1)
}
Re: Can the newly added item be move to the top of a listbox and selected
Thanks for the pretty much straight forward solution.
Re: Can the newly added item be move to the top of a listbox and selected
Probably a better solution , by the way what about delete an item, I know there is a LB_DELETESTRING := 0x0182 counterpart.ntepa wrote: ↑10 Apr 2024, 04:13Another way using SendMessage:Code: Select all
#Requires AutoHotkey v2.0 g := Gui() g.AddText(, "Add a new item:") myEdit := g.AddEdit("w150") g.AddButton("yp", "Enter").OnEvent("Click", AddItemToListBox) myListBox := g.AddListBox("xm r10 w200", ["apple", "orange", "banana"]) g.Show() AddItemToListBox(*) { LB_INSERTSTRING := 0x0181 index := 0 ; wParam is zero-indexed position to insert at SendMessage(LB_INSERTSTRING, index, StrPtr(myEdit.Text), myListBox) myListBox.Choose(1) }
Re: Can the newly added item be move to the top of a listbox and selected
GuiCtrl.Delete(Value) lets you specify the item to delete from a ListBox.
Re: Can the newly added item be move to the top of a listbox and selected
Thank you so much, much appreciatedboiler wrote: ↑11 Apr 2024, 04:52GuiCtrl.Delete(Value) lets you specify the item to delete from a ListBox.
Who is online
Users browsing this forum: No registered users and 26 guests