Search Listbox in REALbasic line

In this quick tutorial we will learn how to search rows and columns in Listbox Control available in REALbasic. You will also find here a tip to execute search after pressing Enter key from keyboard. Watch it, learn it, enjoy it!

Creating the GUI

We will use in this tutorial Listbox Control, TextField Control and PushButton Control. Drag and drop this controls on Window1 Class wherever you like and fill Listbox with some data. If you have no idea what data can you insert there use this code in Listbox1 Sub Open ().

1
2
Listbox1.ColumnCount = 2
Listbox1.InitialValue = "United Nations Day" + chr(9) + "UFC 104" + EndOfLine + "Halloween Costumes" + chr(9) + "Garth Brooks" + EndOfLine + "Los Angeles Angels" + chr(9) + "Hilary Swank" // chr(9) = Tab key

Search Listbox Control

Ok, in this moment we will search in Listbox all data (irrespective of number of rows and columns) to find our words for search. Add to PushButton1 Sub Open () some code… Please have in mind that our search code can return more than one result.

1
2
3
4
5
6
7
8
9
10
11
Dim i, c As Integer
 
for i = 0 to ListBox1.ListCount -1 
    for c = 0 to ListBox1.ColumnCount - 1
      if InStr(ListBox1.Cell(i,c), TextField1.Text)  < > 0 then // different from 0 
        ListBox1.CellBold(i,c) = true // make the text bold
      else
        ListBox1.CellBold(i,c) = false 
      end if
    next
next

Enter key event in TextField Control

To know if the users is pressing the Enter key in TextField go to code editor TextField Function Key Down () and enter there:

1
2
3
if key = chr(13) then 
// code from Search Listbox Control
end if

Author: Jakub Pawlak

I'm interested in all. Currently working on the development of TUTSPOLIS and I hope that in near feature the project will be successful.

12 Responses to “Search Listbox in REALbasic”

  1. marcel says:

    hi Jacob,
    i started with realbasic a while ago and everytime i stop doing it again because i dont find a good place to learn but here i see you update regulary so now i start doing it untill i learn all.
    do you have something like icq or so, so i can add you to my list in case i have questions?
    i realy are motivated to learn it now
    REGARD MARCEL

  2. Jakub Pawlak says:

    Hello Marcel,

    nice to hear that you are now motivated to learn REALbasic :) The best way to contact me is by email or Skype (login is the same like me email).

  3. marcel says:

    i try to find your email since i wrote to you but i still can find you on skype,please send me it by email to contact me on mmeuldijk on skype.

    greetings marcel

    btw keep up the good job so maybe in the future i can help out more here if i know more.

  4. Rivo says:

    is textfield is equal with editfield.??
    I have older version of RB. Thanks

  5. Jakub Pawlak says:

    Yes, this is the same control.

  6. rberrios says:

    Can you post the project? I tried this, but is not working for me.. I get nada… Thanks!

  7. Jakub Pawlak says:

    Hello,

    ok, I will add this project tomorrow if this is no problem :)

    Regards
    Jakub

  8. Jakub Pawlak says:

    The file send you on mail and tutorial fixed :)

  9. chrisjk says:

    Your Paypal page comes up in Polish – I need to see an English page if I am to use it.

  10. Jakub Pawlak says:

    Hello chrisjk,

    I don’t know why this page is now in Polish. You must enter there you email and password and then click Zaloguj sie (login) to go to the payment page.

  11. Jakub Pawlak says:

    hello chrisjk, changed to english version :)

Leave a Reply

Copyrights (c) TUTSPOLIS | Powered by Wordpress MU | Inspired at Elegant Themes designed by qbap (HTML5 & CSS3)