ListBox (very old ListBox behaviour)

That is now several years that a “souvenir” raise about what could have been an old (very old) ListBox auto feature.

I seems to remember pressing a letter (when the ListBox have the Focus) and see the first Row (Column 0 or only one Column ListBox or…) highlighted.

If this souvenir is correct, this can be with REALbasic version 1 (or so).

is this a true souvenir or a dream ?

Pardon ?

I think, long time ago, at REALbasic release 1 or so, that when you have a one Column ListBox full of entries (starting with a letter), when you pressed a, you will get the first Row who text start with a “a” highlighted, same with b, 'till z just what the Finder does for us since… ages…

Is my memory working fine or am I dreamng ?

ListBox KeyDown

dim i, start as integer
  if me.listIndex > -1 then
    if left(me.Cell(me.listIndex, 0), 1) = key then
      start = me.listIndex + 1
      start = 0
      me.listIndex = -1
    end if
  end if
  for i = start to me.listcount - 1
    if left(me.Cell(i, 0), 1) = key then
      me.listindex = i
      return true
    end if
  return true

Thank you Axel.

My archives before 2002-12 are on a storage box, 1,000 Km from here and so I cannot make any search. That is why I asked the question here.

No one remembers ?

something like TypeSelectListbox??

TypeSelectListbox: I do not recall that.


your code works fine (a bit strange, but fine).

The first text file I loaded had… numbers in Column 0 (the project I can really use it is in an external hard disk and I do not had time to get it, so I took the first found project that use ListBox !

So, I added a way to use the code on the selected Column and it works as advertised: it displays the Row that have the first u, and a nother attempt displau the next one, etc.

FWIW: I added in the main project a search module that allows me to search in the whole ListBox contents (and even in two or more columns if each text is separated with a \tab character…)

Nice to code, surprising to use it (the multi column search was a surprise for me !).

Thanks a lot !

Hi Emile,

how do u make it search for multi column?


a. Axel’s shared code:
In the SortColumn event of the ListBox, I set the Column to a global property (gSelCol) and I pass that to Me.Cell(me.listIndex, 0):

me.Cell(me.listIndex, gSelCol)

b. Search text inside a ListBox:
Imagine you have a Row that holds peoples personal info like:
Emile Schwarz Birth Date Address etc.

In the search routine, you pass “Emile Schwarz” as search string (the character between first name and family name is a tab).

Ask if I am not crystal clear.

Emile, I wonder if you weren’t recalling the functionality of a PopupMenu rather than a ListBox.


I do not understand. Can you elaborate the question a bit more ?

When you type a letter into a popupmenu, it will by default search for the first instance of that letter and display the corresponding entry in the list. It sounds like the behavior you described. I’m wondering if you recalled that functionality, but thought it applied to a listbox instead of a popupmenu.


I understand. No, I do not think so. I am not even sure that I knew we can do that with PopupMenus ! ;-:slight_smile: