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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

1001 Things about VFP

Status
Not open for further replies.

crewchiefpro5

Programmer
Dec 17, 2004
33
0
0
US
I know this is basic, however, I am missing something simple.

I am trying to teach my brother how to highlight a grid and I was using 1001 Things book, chapter 6 page 163.

Seems I cannot get the error messages to stop. What am I missing? I just want to highlight the grid row. I have not used this before because I still use my old foxpro sql to array screen that displays rows already highlighted (built with old foxpro code).


Don Higgins
Crew Chief Pro Racing Analysis Software
 
crewchiefpro5,

If you are trying to highlight multiple rows based on the data then perhaps the following FAQ would shed some light on it for you...

Multiselect Records in a Grid - Basic Example
faq184-3831


If you are instead trying to just highlight the active row in a pre-vfp8 version (VFP8 Grid has this functionality already) then perhaps take a look at the following FAQ...

How to make grid display current row in distinct color?
faq184-1264

boyd.gif

 
Hi Don.

Seems I cannot get the error messages to stop

What error messages are you getting?

Here are the steps:

1. Create a custom text box called txtGrid Like so:

Code:
DEFINE CLASS txtgrid AS textbox
  BorderStyle = 0
  Height = 18
  Margin = 0
  SelectOnEntry = .F.
  SpecialEffect = 1
  Width = 100
  Name = "txtgrid"

  PROCEDURE DblClick
    *** Send it up to the grid's dblclick
    This.Parent.Parent.dblClick()
  ENDPROC

  PROCEDURE GotFocus
    TextBox::GotFocus()
    This.SelStart = 0
    This.SelLength = LEN( This.Text )
    NODEFAULT
  ENDPROC

  PROCEDURE When
    *** This code makes sure that the active row is highlighted
    WITH This.Parent.Parent
      .nRecNo = RECNO( .RecordSource )
    ENDWITH
ENDPROC
ENDDEFINE

Now create a grid class that looks like this:

Code:
DEFINE CLASS grdbase AS grid
  DeleteMark = .F.
  Height = 200
  HighlightRow = .F.
  RecordMark = .F.
  ScrollBars = 2
  Width = 371
  *-- Holds the number of the record in the current row of the grid
  nrecno = 0
  Name = "grdbase"

  *-- Keeps highlight on current row when focus leaves the grid
  labout2leavegrid = .F.

  *-- Do anything special that must be done to setup the grid (like hightlight the active row)
  PROCEDURE setgrid
    *** Set up for highlighting current row
    This.nRecNo = RECNO( This.RecordSource )
    This.SetAll( 'DynamicForeColor', ;
      'IIF( RECNO( This.RecordSource ) = This.nRecNo, RGB( 0, 0, 128 ), RGB( 0, 0, 0 ) )', 'COLUMN' )
    This.SetAll( 'DynamicBackColor', ;
      'IIF( RECNO( This.RecordSource ) = This.nRecNo, RGB( 0,255,255 ), RGB( 255, 255, 255 ) )', 'COLUMN' )
  ENDPROC

  PROCEDURE Init
    This.SetGrid()
  ENDPROC

  PROCEDURE Valid
    This.lAbout2LeaveGrid = .T.
  ENDPROC

  PROCEDURE When
    This.lAbout2LeaveGrid = .F.
  ENDPROC

  PROCEDURE BeforeRowColChange
    LPARAMETERS nColIndex
    IF NOT This.lAbout2LeaveGrid 
      This.nRecNo = 0
    ENDIF
  ENDPROC
ENDDEFINE

Now, when you drop one of these grid classes on a form, you must drop the custom text box into each of its column and use that instead of VFP's native text box.

Also, what version of VFP are you using? In version 8 and later, current row highlighting is native.



Marcia G. Akins
 
The book had a WITH THIS but no ENDWITH which I corrected but the problem was not placing the custom text box on the form first.

Thanks to all who answered.



Don Higgins
Crew Chief Pro Racing Analysis Software
 
Hi Don.

The book had a WITH THIS but no ENDWITH which I corrected but the problem was not placing the custom text box on the form first.

I assume that you are talking about the text in the book and not the sample code. Hopefully, something this obvious would not have gottem by Andy, John and me ;-)



Marcia G. Akins
 
>>I assume that you are talking about the text in the book and not the sample code. Hopefully, something this obvious would not have gottem by Andy, John and me
<<

There is one thing we can be sure of... You simply don't make mistakes in your code. The book has some minor issues but they are easily understood normally. This one got me because I didn't READ all of it properly.

Normally when I cannot get something to work while reading this book is because my spelling. I love the book and the help you and Andy have given us over the years.


Don Higgins
Crew Chief Pro Racing Analysis Software
 
In my opinion this book is a 'must have' for all serious VFP-fans.
-Bart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top