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!

How do I get a grid cell to display a modified value? 1

Status
Not open for further replies.

mkrausnick

Programmer
Apr 2, 2002
766
0
0
US
Pulling dates from SQL Server and displaying in a grid. SQL Server dates come down as data type 'T' with the time included. I want to display just the date, so I execute this code:
Code:
FOR nIndex=1 TO Thisform.Grid1.ColumnCount
	IF VARTYPE(Thisform.Grid1.Columns[nIndex].Controls[2].Value) = "T"
		Thisform.Grid1.Columns[nIndex].Controls[2].Value = TTOD(Thisform.Grid1.Columns[nIndex].Controls[2].Value)
	ENDIF 
NEXT nIndex 
Thisform.Grid1.Refresh()
When I run it in the debugger I can see the value and datatype change, but the grid still displays the long format including the time.

How can I display just the date?


Mike Krausnick
Dublin, California
 
Hi

You dont have to change the value as per the code you use.
Instead, set the columns, Format property to Date format. This will make the date appear in date format.

:)

____________________________________________
ramani - (Subramanian.G) :)
 
Thanks for the response. Sorry it took me so long to get back to this project. Setting the format to 'D' had no effect - the date still displays with the time.

More information: I'm building the grid on the fly, assigning the controlsource at runtime and using the SQL Server field names as the column headings.

The frustrating thing is that the format changes I make appear only when I click in the modified cell. Otherwise the format doesn't change. For example, if I code:
Code:
FOR nIndex = 1 TO FCOUNT("c_EnrollDates")
	WITH Thisform.Grid1.Columns[nIndex]
		.Alignment	= 2	&& Middle Center
		.FontBold 	= .T.
		.FontSize	= 11
		.ReadOnly	= .T.
	ENDWITH 
	WITH Thisform.Grid1.Columns[nIndex].Header1
		.Caption = STRTRAN(FIELD(nIndex),'_',' ')
		.Alignment	= 2	
		.FontBold	= .F.
		.FontSize	= 7
		.WordWrap	= .T.
	ENDWITH 
[b][red]	WITH Thisform.Grid1.Columns[nIndex].Text1 
		.Alignment	= 2	
		.DateFormat = 9		&& mm-dd-yy
		.Forecolor	= 255
	ENDWITH [/red][/b]
NEXT nIndex

The cell is not centered nor red when viewed, but is centered and red when I click in the cell. And even though I specify DateFormat = 9 (mm-dd-yy) although that's how the date displays, the time still appears.

What should I code if I wanted the whole column to be red and centered ALL the time, not just one cell when it has focus, and is there a way to suppress display of the time portion of the datetime field coming from SQL Server?

Mike Krausnick
Dublin, California
 
Thanks Mike, that was it! After experimenting awhile I came up with this code that removes the time from the grid display when the controlsource is a datetime field:
Code:
	FOR nIndex = 1 TO FCOUNT("c_EnrollDates")
		WITH Thisform.Grid1.Columns[nIndex][b][red]
			IF TYPE(.ControlSource) == "T"
				.ControlSource = "TTOD(" + .ControlSource + ")"
			ENDIF [/red][/b]
			.Alignment = 2		&& Middle Center
			.FontBold  = .T.
			.FontSize  = 11
			.ReadOnly  = .T.[b][red]
			.Sparse    = .F.[/red][/b]
		ENDWITH 
.
.
.

Mike Krausnick
Dublin, California
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top