Page 1 of 1

Incremental search in listbox without sort

Posted: 12 Apr 2020, 09:08
by jkeks
this hack use edit.
Edit component let you do incremental search by any char in lines, not only first char. And thats cool !
you just need this little function:

Code: Select all

Gui Add, Edit,    ge1 x1   y1  w180 h20 r1 vSearch
Gui Add, ListBox,     x1   y21 w180 h400   vSite   hwndSite, %sites%

...

; on edit change
e1:
	Gui,Submit,NoHide
	sitesArr := StrSplit(sites, "|")
	newArr   := []
	newStr   := ""
	for k,v in sitesArr
	{
		if InStr(v, Search, false)>0
		{
			newArr.push(v)
		}
	}
	for k,v in newArr
		newStr .= "|" v
	GuiControl, , Site, % newStr
	GuiControl, Choose, site, 1
Return
I like it little hack :wave:

Re: Incremental search in listbox without sort

Posted: 13 Apr 2020, 08:13
by burque505
@jkeks, thank you. Working great here!
Regards,
burque505

Re: Incremental search in listbox without sort

Posted: 14 Nov 2020, 18:19
by burque505
@jkeks, I had forgotten how much I liked your hack. Here is a mod that clears the search box when the string isn't found. May not be necessary, but it's useful for me.

Code: Select all

sites := "cnn.com|autohotkey.com|google.com|robin-language.org"
sitesArr := StrSplit(sites, "|")
Gui Add, Edit,    ge1 x5   y5  w185 h20 r1 vSearch
Gui Add, ListBox,     x5   y+5 w185 h400   vSite   hwndSite, %sites%
Gui, Show, w195, jkeks

e1:
	Gui,Submit,NoHide
	if !(InStr(sites, Search, false)) {
	#Persistent
	ToolTip, Search string '%Search%' not found.
	SetTimer, RemoveToolTip, 2000
	GuiControl, , Search
	return
	}
	sitesArr := StrSplit(sites, "|")
	newArr   := []
	newStr   := ""
	for k,v in sitesArr
	{
		if InStr(v, Search, false)>0
		{
			newArr.push(v)
		}
	}
	for k,v in newArr
		newStr .= "|" v
	GuiControl, , Site, % newStr
	GuiControl, Choose, site, 1
Return

GuiClose:
Escape::
ExitApp


RemoveToolTip:
ToolTip
return
Regards,
burque505

Re: Incremental search in listbox without sort

Posted: 14 Nov 2020, 19:22
by Greast
@burque505
Hi! Sorry to ask that, what does this script do exactly?

Re: Incremental search in listbox without sort

Posted: 14 Nov 2020, 20:00
by burque505
@Greast, at the moment it doesn't do anything except demonstrate a fuzzy search. You'll have to handle a GuiEvent to actually see anything, here's a simple MsgBox example.

Code: Select all

sites := "cnn.com|autohotkey.com|google.com|robin-language.org"
sitesArr := StrSplit(sites, "|")
Gui Add, Edit,    ge1 x5   y5  w185 h20 r1 vSearch
Gui Add, ListBox, ge2    x5   y+5 w185 h400   vSite   hwndSite, %sites%
Gui, Show, w195, jkeks

e1:
	Gui,Submit,NoHide
	if !(InStr(sites, Search, false)) {
	#Persistent
	ToolTip, Search string '%Search%' not found.
	SetTimer, RemoveToolTip, 2000
	GuiControl, , Search
	return
	}
	sitesArr := StrSplit(sites, "|")
	newArr   := []
	newStr   := ""
	for k,v in sitesArr
	{
		if InStr(v, Search, false)>0
		{
			newArr.push(v)
		}
	}
	for k,v in newArr
		newStr .= "|" v
	GuiControl, , Site, % newStr
	GuiControl, Choose, site, %A_%
Return

e2:
	if (A_GuiEvent = "DoubleClick")
	{
			ControlGet, listText, Choice, ,ListBox1, jkeks
			msgbox %listText%
	}

GuiClose:
Escape::
ExitApp


RemoveToolTip:
ToolTip
return
Regards,
burque505

Re: Incremental search in listbox without sort

Posted: 14 Nov 2020, 20:06
by Greast
@burque505
Actually, it is a good code.

Re: Incremental search in listbox without sort

Posted: 15 Nov 2020, 11:10
by burque505
@Greast, :thumbup: Thanks! Credit goes to @jkeks, though.
Regards,
burque505