Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listbox Highliting

Status
Not open for further replies.

manpaul

Technical User
Jan 10, 2005
118
CA
I would like to highlight an item on a listbox. I do a seek to find the item and place the pointer on the right record. All i want to to is now have this record highlited in the listbox. If I click on the list box in is highlighted, but when I do the seek I requery, then refresh and it will not highlite the item. Any suggestions
 
Hi manpaul,

Try using the ListItemId property of the listbox. Here's a runnable example...
Code:
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN

DEFINE CLASS form1 AS form

	Top = 0
	Left = 0
	Height = 242
	Width = 375
	DoCreate = .T.
	Caption = "Form1"
	Name = "Form1"

	ADD OBJECT list1 AS listbox WITH ;
		Height = 181, ;
		Left = 25, ;
		Top = 11, ;
		Width = 324, ;
		Name = "List1"

	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 204, ;
		Left = 264, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Seek 5", ;
		Name = "Command1"

	PROCEDURE Init
		CREATE CURSOR crsTest (numbers C(10), pkid I)
		INSERT INTO crsTest (numbers, pkid) VALUES ("One", 1)
		INSERT INTO crsTest (numbers, pkid) VALUES ("Two", 2)
		INSERT INTO crsTest (numbers, pkid) VALUES ("Three", 3)
		INSERT INTO crsTest (numbers, pkid) VALUES ("Four", 4)
		INSERT INTO crsTest (numbers, pkid) VALUES ("Five", 5)
		INSERT INTO crsTest (numbers, pkid) VALUES ("Six", 6)
		INSERT INTO crsTest (numbers, pkid) VALUES ("Seven", 7)
		INSERT INTO crsTest (numbers, pkid) VALUES ("Eight", 8)
		INSERT INTO crsTest (numbers, pkid) VALUES ("Nine", 9)
		INDEX on pkid TO crstest
		SET ORDER TO pkid
		GO TOP IN "crsTest"
		this.list1.RowSource = "crsTest.numbers,pkid"
		this.list1.RowSourceType=6
		this.list1.BoundColumn=2
		this.list1.BoundTo=.T.
		this.list1.ListIndex = 1
	ENDPROC

	PROCEDURE command1.Click
		*!* Instead of
		*!*	=SEEK(5, "crsTest", "crsTest")
		*!* use something like...

		thisform.list1.ListItemId = 5

		*!* record pointer is still moved in the table
		*!* Messagebox(crsTest.pkid)
	ENDPROC

ENDDEFINE

boyd.gif

SweetPotato Software Website
My Blog
 

Manpaul,

Assuming your are populating the listbox from a cursor or table without any deleted or out-filtered records, then the listbox's ListIndex property will match the selected item's Recno(). So, immediately after doing the seek, you can do this:

Code:
IF FOUND()
  THISFORM.Listbox1.ListIndex = RECNO()
ELSE
  THISFORM.Listbox1.ListIndex = 0
ENDIF

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
The table is filtered and records are deleted
 

Manpaul,

The table is filtered and records are deleted

In that case, create a cursor containing only the un-filtered and un-deleted records. This won't affect performance, provided you don't have more than two or three hundred records. And if you do have more than three hundred records, you definitely shouldn't be using a listbox.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
That is what I am trying, thanks for the advice

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top