Format Property
Description
Stores the string used for extra formatting of the caption text.
Property Type
Read-write property
Syntax (Visual Basic)
Public Property Format() As String
Remarks
Formatting Numbers
If the format string is set, the caption text will be formatted according to this format string before drawing it. The format string uses a C-like style, similar to the sprintf() C++ function.
Only the "%s" type is supported with the Format method. This means that the Format method will only format strings and treats all numeric values as strings. If a numeric format is desired and cannot be displayed properly as a string, do not enter a Format string. You will need to manually format your data and set this to the Caption property in the desired string format.
Example Format Strings
The following table illustrates example format strings and their effect on the output (if no Caption has been set):
| Format String | Item Value | Output |
|---|---|---|
| "$ %s" | 3.15 | "$ 3.15" |
| "%s%%" | 25 | "25%" |
| "$ % 8s" | 4.3 | "$ 4.3" |
| "$ %.4s" | 24.0536 | "$ 24.0" |
| "%09s" | .1253 | "0000.1253" |
| "%06.4s" | 3.14325 | "003.14" |
| "My name is %s" | John | "My name is John" |
| "The %s crossed the road" | chicken | "The chicken crossed the road" |
Formatting Dates
If the item will hold a date value, the Format property can be used to format the date.
The following are valid format flags for date values:
%aAbbreviated weekday name%AFull weekday name%bAbbreviated month name%BFull month name%cDate and time representation appropriate for locale%dDay of month as decimal number (01 - 31)%HHour in 24-hour format (00 - 23)%IHour in 12-hour format (01 - 12)%jDay of year as decimal number (001 - 366)%mMonth as decimal number (01 - 12)%MMinute as decimal number (00 - 59)%pCurrent locale's A.M./P.M. indicator for 12-hour clock%SSecond as decimal number (00 - 59)%UWeek of year as decimal number, with Sunday as first day of week (00 - 53)%wWeekday as decimal number (0 - 6; Sunday is 0)%WWeek of year as decimal number, with Monday as first day of week (00 - 53)%xDate representation for current locale%XTime representation for current locale%yYear without century, as decimal number (00 - 99)%YYear with century, as decimal number%z,%ZTime-zone name or abbreviation; no characters if time zone is unknown%%Percent sign%#cLong date and time representation, appropriate for current locale (e.g., "Tuesday, March 14, 1995, 12:41:29").%#xLong date representation, appropriate to current locale (e.g., "Tuesday, March 14, 1995").%#d,%#H,%#I,%#j,%#m,%#M,%#S,%#U,%#w,%#W,%#y,%#YRemove leading zeros (if any).
Example
Number Format Sample (Visual Basic)
This sample illustrates how to use the Format method to format numbers.
Dim Record As GridRecord
Dim Item As GridRecordItem
' Adds a new record/row to the GridControl
Set Record = wndGridControl.Records.Add
' Adds a GridRecordItem with a value of "RE: Your Invoice" to the new GridRecord referenced in the Record variable
Record.AddItem "RE: Your Invoice"
' Adds a GridRecordItem with a value of "John Smith" to the new GridRecord referenced in the Record variable
Record.AddItem "John Smith"
' Adds a GridRecordItem with a value of "19/06/2004" to the new GridRecord referenced in the Record variable
Record.AddItem "19/06/2004"
' Adds a GridRecordItem with a value of "25" to the new GridRecord referenced in the Record variable
Set Item = Record.AddItem("25")
' The value of "25" will now be displayed in the format "25 kb"
Item.Format = "%s kb"
' Add the record/row to the GridControl
wndGridControl.Populate
See Also
Copyright (c) 1998-2024 Codejock Technologies. All rights reserved.