[Gambas-user] Filtering listbox list

T Lee Davidson t.lee.davidson at gmail.com
Sun Mar 11 08:11:12 CET 2018


On 03/10/2018 09:23 PM, Shannon Kuchler wrote:
> 
> 
> Using Gambas 3.10 I'm looking for a way to filter the content of a ListBox using TextBox_KeyPress()
> 
> 
> I know it can be done, but honesty have no idea where to start.

Just to be clear, are you saying that you want to filter the List of a ListBox based on the Text property of a TextBox? (I
actually have to wonder how you know it can be done.)

ListBox has no 'mask' property. So, since ListBox.List is a string array, you would have to:
1. maintain a separate string array,
2. fill the ListBox.List from that original array,
3. on a key event, clear the List and then refill it incrementally from the original array using String[].Find (with Mode=gb.Like).

If you instead are wanting to do incremental searching, you can do that relatively easily by setting the ListBox.Index with
ListBox.Find. But, you'll want to use the KeyRelease event.

[code]
Public Sub Form_Open()

  With ListBox1
    .List = ["abcd", "abce", "abde", "bcde", "bdef"]
    .Mode = Select.Single
  End With

  TextBox1.SetFocus

End

Public Sub TextBox1_KeyRelease()

  ListBox1.Index = ListBox1.Find(TextBox1.Text & "*", gb.Like)

End
[/code]


-- 
Lee


More information about the User mailing list