Somebody2


I have a form with a listbox and a textbox. The listbox displays the contents of a table and is indexed by a name field in alphabetical order, so it displays all of the names in alphabetical order. I want to text box to modify the selection of the listbox. Is it possible to reindex so that the names would start with a different letter Say for example that I input R. Can I get it to index so the first name in the listbox starts with R instead of A. Or would it be easier just to leave the original index the way it is and somehow have the selected item in the listbox jump down the list to R

Example -

Listbox Contents:

Anna

Betty

George

Jim

Joe

Teddy

I type a G into the textbox. Is it possible to reindex so that George is now the first name in the list, or is it easier to have the selection jump to George The selection when the form is initialized is Anna because it selects the first item.



Re: Index On

dni


You may need to feed list box from a cursor ordered by first letter from textbox.







Re: Index On

Naomi Nosonovsky

What is the RowSource for the Listbox If it's a cursor already indexed the way you want, say, by name, then

Code Snippet

set exact off

if seek(m.lcLetter,'MyCursor','NameTag')

thisform.List1.ListIndex = recno('myCursor')

endif

You can slightly modify this code to use Locate instead of SEEK.

Bellow is my colleague's code for a listbox populated with AddItem (or value) and small number of items:

Code Snippet

with this
lcSearchString = alltrim(lower(.txtSearch.Value))
endwith
if len(lcSearchString) = 0
lcMsg = 'You must enter a search string.'
=MESSAGEBOX(lcMsg, MB_OK + MB_ICONEXCLAMATION, lcTitle)
this.txtSearch.SetFocus()
return
endif
llFound = .F.
with this.List1
if this.cmdSearch.Caption = 'Search Again'
lnStartAt = .ListIndex + 1
else
lnStartAt = 1
endif
if lnStartAt <= .ListCount
for i = lnStartAt to .ListCount
if lcSearchString $ lower(.List[i])
llFound = .T.
.ListIndex = i
exit
endif
endfor
endif
endwith






Re: Index On

Somebody2

The RowSourceType is 6. The RowSource is names.last, first, pin.





Re: Index On

Naomi Nosonovsky

I see. You may try slightly different variation of my original code:

set exact off

if seek(m.lcLetter,'myTable','myNameTag') && alternatively you can use LOCATE FOR Name = m.lcLetter

thisform.ListBox.value = myTable.Name

endif

From the top of my head (not tested).





Re: Index On

Somebody2

I suppose I could modify things a bit and use

Code Snippet

thisform.List2.RowSourceType = 3

thisform.List2.RowSource = "SELECT last, first FROM names WHERE last LIKE m.lname+"%" INTO cursor info"

m.lname would be the controlsource of the textbox. This way it would keep updating the items in the listbox with the info from the select statement. This is probably incorrect syntax, so I would have to play around with the m.lname+"%" part to get it to work right.




Re: Index On

Naomi Nosonovsky

Check Cetin Basoz reply in your previous thread.

If you do SET ANSI OFF

Create a new property cLast_Name for your listbox in its Init, e.g.

this.AddProperty('cLast_Name','A') && Let's start with the A names first

this.RowSource = [Select Last, First from Names where Last = this.cLast_name into cursor curInfo]

then all you would have to do when changing a name is to assign thisform.lstNames.cLast_Name = alltrim(thisform.txtSearch.value)

thisform.lstNames.Requery() should work.