[Gambas-user] Filtering listbox list
Shannon Kuchler
shannon at inflecto.org
Sun Mar 11 22:03:08 CET 2018
This code works
Public Sub TextBox4_KeyRelease()Dim i As Integer
Dim l As Integer
i = (-1)
ListBox6.Clear
If TextBox4.Text = "" Then ListBox6.List = ListBox1.List
If TextBox4.Text <= " " Then Return ' not searchable
For l = 0 To ListBox1.List.Max
Inc i
If ListBox1[i].Text Like TextBox4.Text & "*" Then ' found another
ListBox6.Add(ListBox1[i].Text)
Endif
Next
end
I could not get it to work with out the "Inc i" perhaps I'm missing something there. Before it wasn't catching listbox1.index(0) so I had to add "i = (-1)"However it still need something because it only 1/2 works
for instance this is the data in listbox1
The Dying Lands
Bad Company
Valmod Expansion Pack
Valmod Overhaul Pack
Darkness Falls (BBP)
Starvation
War Of The Walkers 5.2 (BBP)
if I type "v" in textbox4 I get this output to listbox6 which I expected
Valmod Expansion Pack
Valmod Overhaul Pack
However if I type "t" in textbox4 I get this output to listbox6
The Dying Lands
I expected 't" to give me everything that had a 't' like this
The Dying LandsStarvationWar Of The Walkers 5.2 (BBP)
Good advice on using ListBox.List.Max.
I have found the KeyRelease event to be more reliable in regards to having access to the actual, current keystroke value.
And, instead of looping through List, I personally would simply use ListBox.Find.
--
Lee
On 03/11/2018 09:37 AM, Gianluigi wrote:
> Maybe you could use the KeyPress event with "If Key.Code = Key.Return Then ...",
> "Inc i" is useless and you should use ListBox1.List.Max (or ListBox1.count -1) instead of ListBox1.Count to avoid the 'out of
> bound' error.
>
> Regards
> Gianluigi
>
> 2018-03-11 10:33 GMT+01:00 Shannon Kuchler <shannon at inflecto.org <mailto:shannon at inflecto.org>>:
>
> __
>
>
>
> -I think I figured it out
>
>
> Public Sub TextBox4_KeyRelease()
> Dim i As Integer
> Dim l As Integer
>
> ListBox6.Clear
>
>
> If TextBox4.text > "z" Or TextBox4.text < " " Then Return
> For l = 0 To ListBox1.Count
> Inc i
> If ListBox1[i].Text Like TextBox4.Text & "*" Then ' found another
> ListBox6.Add(ListBox1[i].Text)
> Endif
> Next
>
> End
>
>
>
--------------------------------------------------
This is the Gambas Mailing List:
https://lists.gambas-basic.org/listinfo/user
Search the list:
https://lists.gambas-basic.org/cgi-bin/search.cgi
Hosted by https://www.hostsharing.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180311/cbe7a6aa/attachment-0001.html>
More information about the User
mailing list