Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Stefan Wuebbe
  Where is Stefan Wuebbe?
 Hamburg
 Germany
 Stefan Wuebbe
 To: Frank Smith
  Where is Frank Smith?
 Houston
 Texas - United States
 Frank Smith
 Tags
Subject: RE: ListBox help needed
Thread ID: 331329 Message ID: 331360 # Views: 66 # Ratings: 2
Version: Visual FoxPro 9 SP2 Category: Forms
Date: Thursday, December 29, 2011 8:49:20 AM         
   


> Ok, been away from VFP for a while.
>
> Have a ListBox with a source of "members.dbf"
> In another area of code I locate a record in members and issue a List1.Click()
> The Click() does what it is supposed to do BUT
> the chosen record in the ListBox is not highlighted... can be confusing
> to the User.
>
> how do I get the chosen record in the listbox to highlight?


Since Click() is an event, calling Click() prgrammatically does not raise the event itself and if there is no custom code in the so called "event method", even nothing would happen at all (same for other events like Init, Destroy, Activate, Load and so on).
With a ListBox, you can use properties like .ListIndex or .Selected() instead, see also the runnable sample pasted below.

PS: IMO in most cases the Grid class is easier to use than ListBox - for example in your particular case it would as well display any externally raised record pointer movement in its RecordSource automatically as well as moving the record pointer as soon as a new row is being clicked in the Grid itself.


hth
-Stefan


LOCAL oForm as Form
oForm = CREATEOBJECT('TestForm')
oForm.Show(1)
RETURN

DEFINE CLASS TestForm as Form
	AutoCenter = .T.
	PROCEDURE Load
		CREATE CURSOR temp (test Char(20))
		INDEX on LOWER(test) TAG test COLLATE 'machine'
		INSERT INTO temp VALUES ('Adam')
		INSERT INTO temp VALUES ('Bill')
		INSERT INTO temp VALUES ('Charlie')
		INSERT INTO temp VALUES ('David')
		INSERT INTO temp VALUES ('Edward')
	ENDPROC

	ADD OBJECT txtSearch as Textbox WITH ;
		Left = 20, Top = 10
	PROCEDURE txtSearch.InterActiveChange
		LOCAL lcExact
		lcExact = SET("Exact")
		SET EXACT OFF	&& default, 'ON' would require typing the whole "word", your choice
		IF NOT EMPTY(This.Value) AND SEEK( LOWER(TRIM(This.Value)), 'temp','test' )
			Thisform.List1.Selected( RECNO('temp') ) = .T.
		ELSE
			Thisform.List1.ListIndex = 0
		ENDIF
		SET EXACT &lcExact
	ENDPROC

	ADD OBJECT List1 as Listbox WITH ;
		Left = 20, Top = 40, RowSourceType = 2, ;
		RowSource = 'temp.test'
ENDDEFINE


ENTIRE THREAD

ListBox help needed Posted by Frank Smith @ 12/29/2011 1:07:08 AM
RE: ListBox help needed Posted by Jun Tangunan @ 12/29/2011 1:33:31 AM
RE: ListBox help needed Posted by Stefan Wuebbe @ 12/29/2011 8:49:20 AM
RE: ListBox help needed Posted by Frank Smith @ 1/18/2012 3:54:50 PM
RE: ListBox help needed Posted by Anders Altberg @ 1/18/2012 6:59:02 PM
RE: ListBox help needed Posted by tushar @ 1/19/2012 5:45:10 AM