Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
OTHER >>  DATA DRIVEN SIMPLELIST OLE CONTROL

  Don Higgins
  Where is Don Higgins?
 Peoria
 Illinois - United States
 Don Higgins



Mike Lewis has a great SimpleList Control available on his web site at http://www.ml-consult.co.uk/foxstuff.htm I use this control all the time to display data and allow the user to select a record. I find it is easier than creating a grid or listbox in FoxPro.

I have added the ability to add, remove, adjust the size, and change the order of fields displayed in this control.

The current control requires this syntax in the INIT():

DODEFAULT()

SELECT *, IIF(inewused="N","New ","Used") as neworused ;
    FROM invrey ;
    ORDER BY IYEAR DESC,IMODEL,IDAYS DESC ;
    INTO CURSOR csrInventRey NOFILTER READWRITE



* update count
thisform.pageframe1.inventoryPage.txtInventoryCount.Value = _tally


WITH THIS
    .cAlias = "csrInventRey"
    .cData = "imodel,imod10no,istocknum,iyear,icolor,ilistprice,icost,idays,imodno,imake,neworused"
    .cColumnHeaders = "Model,Type,Stock #,Year,Color,List Price,Cost,Days,Model #,Make,New/Used"
    .lFullRowSelect = .T.
    .lgridlines = .T.
    .lhottracking = .T.
    .lsorted = .T.
    .ccolumnalignments = "L,L,L,C,C,C,L,L,L,L,C"
    .cColumnWidths = "155,135,80,50,80,80,80,50,100,80,80"
    ** .height = 360

    .nInitialSortDirection = 1
    .ninitialsortcolumn = 4

    .populateList
    .SelectItem(1)
ENDWITH


This is fine, EXCEPT if the user wants something else. I decided to give them a choice.

The trick is to add a database called FLDLIST.DBF that stores the Description, Field Name, Column Header, Width, Show Field, and Field Display Order. The FldName field contains the actual name of fields in the driving table. This way the end user can see what info is available to review and add it, remove it, widen it, or change the description in the column.

For Example: I design a racing software program. In my search forms I have a bunch of info displayed. Some users don't want this much info or want something different. Now they click on an Options Command Button and change it. So if they want to see their Miles Per Hour field along with Density Altitude, Vapor Pressure, and Dew Point then they get exactly that. If the next user wants to see more that what I give them they can instantly get it. Everyone gets what they want, not too much, nor too little.


Now in the init() of the control I can set the display exactly how the user wants it. Here is how it is done.

DODEFAULT()

* expand control to full width of screen space - 50 pixels. I have already widened the search screen to the full width of the screen space in the init of the form.
THIS.WIDTH = SYSMETRIC(1) - 50

LOCAL  lcData,lcColumnHeaders, lcSelect, lcWidth, lcAlign

* hold current alias selected
lcSelect = ALIAS()

* set local variables defaults
lcData = ""
lcColumnHeaders = ""
lcWidth = ""
lcAlign = ""


* open FIELD LIST database 
* called fldlist.dbf
DO openit IN MAIN WITH "data\fldlist"
SELECT FLDLIST
INDEX on fldorder TAG fldorder
SET ORDER to tag fldorder


* Now loop thru the fldlist.dbf file
* to assemble the field list, descriptions, widths, and alignments
SCAN FOR showfld = .t.
	* assemble the .cData, cColumnHeaders, ccolumnalignments, and ccolumnwidths property
	* note: the iif(empty) clause workings
	* without this there would be a comma before the 
	* data and this does not work.
	* NO Spaces are allowed!
	lcData = IIF(EMPTY(lcData),ALLTRIM(fldname),ALLTRIM(lcData) + "," + ALLTRIM(fldname))
	
	lcColumnHeaders = IIF(EMPTY(lcColumnHeaders),ALLTRIM(fldfullnam),ALLTRIM(lcColumnHeaders) +"," + ALLTRIM(fldfullnam))
	
	lcWidth = IIF(EMPTY(lcWidth),ALLTRIM(fldwidth),ALLTRIM(lcWidth) +"," + ALLTRIM(fldwidth))

	lcAlign = IIF(EMPTY(lcAlign),ALLTRIM(fldalign),ALLTRIM(lcAlign) +"," + ALLTRIM(fldalign))
	
ENDSCAN

* OK we are done with this database
* lets close it so it does not get damaged
* if the power goes off.  Also delete index tag
SELECT fldlist
DELETE TAG all
USE


* reselect previous database
SELECT &lcSelect




WITH THIS
	.cAlias = (lcSelect)
			
	.cData = ALLTRIM((lcData))
	
	.cColumnHeaders = ALLTRIM((lcColumnHeaders))
	
	.ccolumnalignments = ALLTRIM((lcAlign))

	.ccolumnwidths = ALLTRIM((lcWidth))

	.lFullRowSelect = .T.
	.lgridlines = .T.
	.lhottracking = .T.
	.lsorted = .T.


	.ninitialsortcolumn = 1
	.ninitialsortdirection = 1
	.populateList

	.selectitem(1)

ENDWITH




I also have a form called SearchOptions that has a grid on it with all the fields displayed. The end user can change the order, width, description, field name, and add records to it.


Here is a PDF Picture Listing on my website. http://www.crewchiefpro.com/datadrivensimplelist.pdf

Don Higgins
www.crewchiefpro.com

FEEDBACK

Boudewijn Lutgerink @ 3/6/2007 7:21:36 AM
Nice Don, on equestion though. Why not simply keep the index? Indexing and throwing the index away afterwards seem to me like a waste of time. Keeping the index and opening the table WITH the correct index is quite faster

Don Higgins @ 3/21/2007 4:28:11 AM
On a small table such as this I always delete the tag after use. I find less problems with CDX files stopping a DBF from opening properly.

It is just a personal preference.



Your Name: 
Your Feedback: 

Spam Protection:
Enter the code shown: