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

Highlight Grid rows 4

Status
Not open for further replies.

Qwark

Programmer
Sep 26, 2000
59
NL
Hello,

I use a grid in my program. Because it offers a lot more functionality than a listbox, but now i will select (highlight) a whole row just like a list. I have used HighlightRow but that highlight only lines.
When I change the backgroundcolor of the specific textbox only one cell is highlighted, but i want that the whole row is highlighted. How can I do that?

Thanks,

Qwark
 
Hi Qwark,

Have a look at this class definition:

**************************************************
*-- Class: grd_base (d:\cbproject\libs\base_cntrl.vcx)
*-- ParentClass: grid
*-- BaseClass: grid
*-- Time Stamp: 11/24/00 09:51:11 PM
*
#INCLUDE "d:\cbproject\include\app.h"
*
DEFINE CLASS grd_base AS grid


FontName = "MS Sans Serif"
DeleteMark = .F.
GridLines = 2
Height = 200
ReadOnly = .T.
RecordMark = .F.
Width = 320
GridLineColor = RGB(192,192,192)
*-- Stores te current record number of the record source.
rec_no = 0
Name = "grd_base"

*-- Indicates if highlighting should be.
lnohighlight = .F.

*-- Stores a logical indicating if the lockscreen should be used when scrolling.
PROTECTED luselockscreen


PROCEDURE BeforeRowColChange
LPARAMETERS nColIndex
LOCAL llRetVal
IF THIS.lUseLockScreen
THISFORM.LockScreen = .T.
ENDIF

ENDPROC


PROCEDURE Valid
LOCAL llRetVal
llRetVal = DODEFAULT()
IF llRetVal
THIS.lUseLockScreen = .F.
THISFORM.LOCKSCREEN = .F.
ENDIF

RETURN llRetVal
ENDPROC


PROCEDURE When
LOCAL llRetVal
llRetVal = DODEFAULT()
IF llRetVal
THIS.lUseLockScreen = .T.
THISFORM.LOCKSCREEN = .F.
ENDIF

RETURN llRetVal
ENDPROC


PROCEDURE Refresh
DODEFAULT()

THIS.rec_no = RECNO(THIS.RECORDSOURCE)
ENDPROC


PROCEDURE AfterRowColChange
LPARAMETERS nColIndex
LOCAL llRetVal
llRetVal = DODEFAULT(nColIndex)

IF llRetVal
THIS.rec_no = RECNO(THIS.RECORDSOURCE)
ENDIF

IF THIS.luseLockScreen
THISFORM.LOCKSCREEN = .F.
ENDIF

RETURN llRetVal
ENDPROC


PROCEDURE Init
LOCAL llRetVal, lnCounter

llRetVal = DODEFAULT()

IF llRetVal AND !(THIS.lNoHighLight)
THIS.SETALL("DynamicBackColor", "IIF(RECNO(THIS.RecordSource) = THIS.rec_no, 8388608, 16777215)", "Column")
THIS.SETALL("DynamicForeColor", "IIF(RECNO(THIS.RecordSource)= THIS.rec_no, 16777215, 0)", "Column")
IF THIS.COLUMNCOUNT > 0
FOR lnCounter = 1 TO THIS.COLUMNCOUNT
WITH THIS.COLUMNS[lnCounter]
.Text1.BACKCOLOR = 8388608
.Text1.FORECOLOR = 16777215
.Text1.DISABLEDFORECOLOR = 8421504
.Text1.DISABLEDBACKCOLOR = 16777215
ENDWITH
ENDFOR
ENDIF
ENDIF

RETURN llRetVal
ENDPROC

ENDDEFINE
*
*-- EndDefine: grd_base
**************************************************
 
Qwark

Another alternative for you.

Add a new form property called .nRecordNo

In the .Init event of grid1 put:-

THISFORM.nRecordNo = RECNO(
)

WITH THIS
.SetAll([DynamicBackColor],"IIF(RECNO(
)=THISFORM.nRecordNo,RGB(0,0,128),RGB(255,255,255))",[Column])
.SetAll([DynamicForeColor],"IIF(RECNO(
)=THISFORM.nRecordNo,RGB(255,255,255),RGB(0,0,0))",[Column])
.Refresh()
ENDWITH


In the .AfterRowColChange event of grid1 put:-

WITH THISFORM
.nRecordNo = RECNO(
)
.grid1.Refresh()
ENDIF


Chris
 
Tanks, you have make a lot of work of it. ;)
I gona try it now.

Qwark
 
Qwark

If you need to show a grid as disabled at any time, try the following

WITH THISFORM.grid1
[tab].SetAll([DynamicForeColor],"RGB(128,128,128)",[Column])
[tab].SetAll([DynamicBackColor],"RGB(192,192,192)",[Column])
[tab].Enabled = .F.
[tab].Refresh()
ENDWITH


You then need to reverse this to enable the grid

WITH THISFORM.grid1
[tab].Enabled = .T.
[tab].Init()
[tab].SetAll([DynamicBackColor],"IIF(RECNO(
)=THISFORM.nRecordNo,RGB(0,0,128),RGB(255,255,255))",[Column])
[tab].SetAll([DynamicForeColor],"IIF(RECNO(
)=THISFORM.nRecordNo,RGB(255,255,255),RGB(0,0,0))",[Column])
[tab].Refresh()
ENDWITH


Chris

 
on the universal thread page
There is a VCX called - Grid Highlighter
I checked it out a few weeks ago and it works as advertised, but I din't really pound on it very hard.


Grid Highlighter v. 2.0 October 22, 2000 23:36
You said you wanted highlighted row in the grid?
Forget adding properties and code in different places.
Forget creating a special grid class with built-in highlight row functionality.
You don't need to do it anymore.

All you need:

1. Drop the instance of GridHighlighter class beside your grid (at the same level that is)

2. Set GridHighlighter1.cHostname property the same as your Grid.Name (i.e. "Grid1")

3. Add one line of code to your Grid.AfterRowColChange() event:

this.parent.GridHighlighter1.Highlight_Row()

4.(Optional) Set the corresponding GridHighlighter properties if you don't like the default highlight color,or if you want to choose highlight,or boldface(default setting is both).You can also have active column header highlighted.
5. Voila! There you go. :)

GridHighlighter works in VFP 3, 5, 6 and 7.

10/04/2000 - Version 2.0. Completely redesigned.

10/18/2000 Sample forms and README.TXT updated.

-Pete
 
Qwark

Apologies - the second block of code from my last post should have been:-

WITH THISFORM.grid1
.Enabled = .T.
.Init()
.Refresh()
ENDWITH


The .init event of the grid resets the colours.

Chris

 
I'd like to say thank you to "weedz" for his/her CLASS grd_base which I've found very helpful today.

However, I would like to make one suggestion, since I don't want to assume that the textboxes in the columns of my grid are named "Text1"

Instead of this snippet:

Code:
 WITH THIS.COLUMNS[lnCounter]
             .Text1.BACKCOLOR            = 8388608
             .Text1.FORECOLOR            = 16777215
             .Text1.DISABLEDFORECOLOR    = 8421504
             .Text1.DISABLEDBACKCOLOR    = 16777215
 ENDWITH
I replaced it with this:
Code:
  WITH EVALUATE("THIS." + THIS.COLUMNS[lnCounter].Name + "." + THIS.COLUMNS[lnCounter].CurrentControl)
	.BACKCOLOR            = 8388608	&&dark blue
	.FORECOLOR            = 16777215	&&white
	.DISABLEDFORECOLOR    = 8421504	&&dark grey
	.DISABLEDBACKCOLOR    = 16777215	&&white
   ENDWITH
It works, but it doesn't seem the most elegant solution. I tried macro substitution but couldn't get it to work. Any suggestions?

Teresa

P.S. Is this post too old to reply to?
 
To have a different highlighting color of current row in a grid, put the following codes in the Grid Class.
====================================================
MyGrid.InitEvent
================
DODEFAULT()
WITH THIS
.SetAll("DynamicBackColor", ;
"IIF(recno(This.RecordSource)=THIS.inRecno, ;
RGB(0,255,0),RGB(255,255,192))","COLUMN")
ENDWITH
===================================================
MyGrid.WhenEvent
===============
This.inRecNo = RECNO()
RETURN .T.
===================================================

ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
 
I have tried several of the codes for highlighting the rows and I get a message saying " use a valid expression for DYNAMIC BACK COLOR property.

Any ideas.

Thanks for your time
 
HI Gary
Check my FAQ on this
How to make grid display current row in distinct color?
faq184-1264

In all probability, you have not used the "" marks surrounding the RGB code. Hope this solves your problem :)


ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
I have had great success using the highlighting techniques above. However, I run into problems when i place two grids with relationships on the same form. The first grid works, but the second grid gets error message "use valid dynamicback color property"

Any ideas on how to use tweak this code to work on two grids?

Thanks
 
HI Gary,

The following code posted by me shall work for any number of grids. :)
====================================================
MyGrid.InitEvent
================
DODEFAULT()
WITH THIS
.SetAll("DynamicBackColor", ;
"IIF(recno(This.RecordSource)=THIS.inRecno, ;
RGB(0,255,0),RGB(255,255,192))","COLUMN")
ENDWITH
===================================================
MyGrid.WhenEvent
===============
This.inRecNo = RECNO()
RETURN .T.
===================================================
:) ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Hi Ramani,

I got an error when I run a form, which I placed your following code

DODEFAULT()
WITH THIS
.SetAll("DynamicBackColor", ;
"IIF(recno(This.RecordSource)=THIS.inRecno, ;
RGB(0,255,0),RGB(255,255,192))","COLUMN")
ENDWITH

into the Init event and

This.inRecNo = RECNO()
RETURN .T.

into When event,


This error message is,

Expression is invalid. Use a valid expression for DYNAMICBACKCOLOR property.


Would you please let me know how to solve this problem ?


Peter W.



 
You need edit the default settings of recno and inrecno to 0 from .f.


On your form properties go to the bottom and find the properties you have added and modify settings to 0. Zero

 
Qwark

I know this is an old thread, but I came across it and thought I'd post this:

If you just simply want to highlight a whole row in a grid...

Create a form > Place a grid on it > Double click on the grid > in the grids AfterRowColChange property place the following code:

Code:
LPARAMETERS nColIndex
grno = RECNO()
THISFORM.Refresh()

Then in the grids Init property place the following code:

Code:
PUBLIC grno
grno = RECNO()

THIS.setall("Dynamicbackcolor", ;
  "IIF(RECNO()=grno,RGB(0,0,0),RGB(255,255,255))","Column")

THIS.setall("DynamicForecolor", ;
  "IIF(RECNO()=grno,RGB(255,255,255),RGB(0,0,0))","Column")

* Just to help, these are some other colours (RGB Colors - RED 255,0,0 - Green 64,128,128)

When you run the form, the whole row will be highlited black with white text and the rest of the rows will be white with black text

Hope that helps

I'm trying to find a sollution to just highlighting a single "cell" in a row / column, any suggestions? (anyone here on this thread)

Kindest regards
Lee.....


VisFox Version 6 User
 
I'm not sure how far back the HighLightRow property goes back, but you could set that to .F., and use another method such as DynamicForeColor or DynamicBackColor, click, setfocus and so on to highlight a cell.

Take a look at this FAQ:
How do I change grids' row/column colors/fonts, ...
faq184-3098


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top