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!

Using Special Characters in Grid Header

Status
Not open for further replies.

ggrewe

IS-IT--Management
Jul 10, 2001
169
US
I am trying to find a way to display special characters in a grids header. For example;

I have a method written in my grid class that when I click on a grid header, it sorts the grid accordingly. I also change the caption of the header to include an up arrow (^) when the header is first clicked and then a dash (-) when the header is clicked a second time.

It would be nice to be able to display something better than the the dash (-), like the down arrow [chr(24)]. Or better yet, append a nice icon.

Has anyone ever done this?

And if anyone is interested, here is the method I am using...

Code:
LOCAL lcSafety AS Character, lcField AS Character, lcString AS Character, ;
	lcAlias AS Character, loColumn AS Object, nView_Out AS Integer, ;
	nWhere_Out AS Integer, nRelRow_Out AS Integer, nRelCol_Out AS Integer, ;
	nXCoord_In AS Integer,  nYCoord_In AS Integer, lnBuffering, lcSortOrder AS Character, ;
	i as Integer, loHeader AS Object    

nXCoord_In = MCOL(WONTOP(),3)
nYCoord_In = MROW(WONTOP(),3)

STORE 0 TO nWhere_Out, nRelRow_Out, nRelCol_Out, nView_Out
 
IF THIS.GridHitTest(nXCoord_In, nYCoord_In, @nWhere_Out, @nRelRow_Out, @nRelCol_Out)
	loColumn = "THIS.Column" + ALLTRIM(STR(nRelCol_Out)) 	&&& + ".Header1"
	loColumn = EVALUATE(loColumn)

	lcAlias = UPPER(THIS.RecordSource)
	lcString = UPPER(loColumn.ControlSource)
	lcField = STRTRAN(lcString, lcAlias + ".", "")
	lcString = EVALUATE(lcString)
	
	SELECT(lcAlias)
	lnBuffering = CURSORGETPROP("Buffering", lcAlias)
	IF CURSORSETPROP("Buffering", 3, lcAlias)
		lcSafety = SET('SAFETY')
		SET SAFETY OFF
		*
		DO CASE 
		 CASE VARTYPE(lcString) = "C" 
		 	lcSortOrder = "INDEX ON ALLTRIM(" + lcField + ")" 
		 CASE VARTYPE(lcString) = "N" OR VARTYPE(lcString) = "Y" OR VARTYPE(lcString) = "D" ;
		 		OR VARTYPE(lcString) = "T" OR VARTYPE(lcString) = "L" 
		 	lcSortOrder = "INDEX ON " + lcField
		 CASE VARTYPE(lcString) = "Q" OR VARTYPE(lcString) = "G" OR VARTYPE(lcString) = "O" ;
		 		OR VARTYPE(lcString) = "X" OR VARTYPE(lcString) = "U" 
		 	lcSortOrder = loColumn.Header1.Caption
		ENDCASE
		*
		FOR i = 1 TO THIS.ColumnCount 
			IF i <> nRelCol_Out		&&& Reset all Header Captions, except the Header that was clicked
				loHeader = "THIS.Column" + ALLTRIM(STR(i)) 
				loHeader = EVALUATE(loHeader)
				IF "(" $ loHeader.Header1.Caption
					loHeader.Header1.Caption = ALLTRIM(LEFT(loHeader.Header1.Caption, AT("(", loHeader.Header1.Caption)-2))
				ENDIF
			ENDIF
		ENDFOR
		*
		DO CASE
		 CASE '-' $ loColumn.Header1.Caption	&&& Descending, change to Ascending
			loColumn.Header1.Caption = ALLTRIM(LEFT(loColumn.Header1.Caption, AT("(", loColumn.Header1.Caption)-2) + " (^)")
			lcSortOrder = lcSortOrder + " TAG Key ASCENDING"
		 CASE '^' $ loColumn.Header1.Caption	&&& Ascending, change to Descending
			loColumn.Header1.Caption = ALLTRIM(LEFT(loColumn.Header1.Caption, AT("(", loColumn.Header1.Caption)-2) + " (-)")
			lcSortOrder = lcSortOrder + " TAG Key DESCENDING"
		 OTHERWISE	&&& Nothing Set, make Ascending
			loColumn.Header1.Caption = ALLTRIM(loColumn.Header1.Caption) + " (^)"
			lcSortOrder = lcSortOrder + " TAG Key ASCENDING"
		ENDCASE
		*
		IF LEFT(lcSortOrder,5) = "INDEX"
			&lcSortOrder
		ELSE
			=MESSAGEBOX('I am sorry, but I can not sorry this display by the field type "' + ;
				ALLTRIM(lcSortOrder) + '", please select a different column!', 0, "Problem Sorting Display...")
		ENDIF
		GO TOP
		SET SAFETY &lcSafety
		=CURSORSETPROP("Buffering", lnBuffering, lcAlias)
	ENDIF

	THIS.Refresh
	SELECT(THISFORM.rc_MasterAlias)
ELSE
ENDIF



Greg Grewe
West Chester, Ohio
 
All you need to do is add to your code something like:

loColumn.Header1.Picture = ".\icons\up.ico"

(Just change the icon file depending on the case.

Regards,

Rob
 
Hum, I have tried that, but have not had much luck. You have done this and it worked for you? I must have typed something wrong.



Greg Grewe
West Chester, Ohio
 
I just did it and it works great. The grid needs a recordsource with atleast 1 record for it to work. Create a form level variable called: llColumn1Header1Clicked Then in the Header.Click method put something like (or build into your process):


IF thisForm.llColumn1Header1Clicked = .T.
This.Picture = ".\ico\items_grid\alert.png"
ThisForm.llColumn1Header1Clicked = .F.
ELSE
This.Picture = ".\ico\items_grid\check.png"
ThisForm.llColumn1Header1Clicked = .T.
ENDIF

Regards,

Rob
 
Found the problem... I was not specifying the location of the icon file and the location was not in the path statement. When running the form in the IDE, the icon never displayed. After compiling the form, it worked great. Thanks!



Greg Grewe
West Chester, Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top