CGXDateTimeCtrl::AddUserAttributes

static void AddUserAttributes(CGXStylesMap* stylesMap);

stylesMap

Points to the styles-map object.

Remarks

Call this static method to register user attributes with the styles-map. Registered user attributes will be displayed in the CGXStyleSheet and can be modified by the user with the style sheet.

If you don’t want the attributes to be visible in the CGXStyleSheet, you should not call AddUserAttributes. You will still be able to use user attributes in your grid. They will only be hidden from the user in the CGXStyleSheet.

CGXDateTimeCtrl needs some user attributes that specify the behavior of the date/time control. These need to be specified for the control to be able to display itself in the required format. This call will add all the user attributes required for this control.

This snippet shows how the user attributes are added:

void CGXDateTimeCtrl::AddUserAttributes(CGXStylesMap* pStylesMap)

{

pStylesMap->AddUserAttribute(GX_IDS_UA_DATENOEDIT);

pStylesMap->AddUserAttribute(GX_IDS_UA_DATEMIN);

pStylesMap->AddUserAttribute(GX_IDS_UA_DATEMAX);

pStylesMap->AddUserAttribute(GX_IDS_UA_DATEVALIDMODE);

pStylesMap->AddUserAttribute(GX_IDS_UA_DATEFORMATTYPE);

pStylesMap->AddUserAttribute(GX_IDS_UA_CUSTOMFORMAT);

}

Here is a brief explanation of what each attribute stands for and how you can use these attributes to change every aspect of the CGXDateTimeCtrl.

·GX_IDS_UA_DATENOEDIT: This user attribute specifies which of the control attributes are editable

enum NoEdit

{

FixedYear = 0x0001,// The year is non-editable

FixedMonth = 0x0002,// The month is non-editable

FixedDay = 0x0004,// The day is non-editable

FixedHour = 0x0008,// The hour is non-editable

FixedMinute = 0x0010,// The minute is non-editable

FixedSecond = 0x0020// The second is non-editable

};

Each of the gadgets can be made editable or non-editable by changing these attributes.

·GX_IDS_UA_DATEMIN and GX_IDS_UA_DATEMAX: These user attributes are used to specify the minimum and maximum valid dates, which will be enforced by the control when the user enters data.

Example values for these attributes:

//The maximum allowed date

CString strMax(_T("3/2/72"));

CString strMin(_T("3/2/52"));

You can then set these values on the style for the date control cell like this

SetStyleRange(CGXRange(8,1),

CGXStyle()

.SetControl(GX_IDS_CTRL_DATETIME)

.SetUserAttribute(GX_IDS_UA_DATEFORMATTYPE, str)

.SetValue(dt.Format())

.SetUserAttribute(GX_IDS_UA_DATEMAX, strMax)

.SetUserAttribute(GX_IDS_UA_DATEMIN, strMin)

.SetUserAttribute(GX_IDS_UA_DATEVALIDMODE, strValidate)

);

?GX_IDS_UA_DATEVALIDMODE: This user attribute specifies the validation mode for the cell. This will be of type ValidationMode

// The validation types as used by Get/SetMinMax

enum ValidationMode

{

NoValidation,// No validation is required

TimeValidation,// Validation of time fields only

DateValidation,// Validation of date fields only

DateTimeValidation// Validation of date & time fields

};

This can be set to any of the above values. The following ids representing the above are already defined in the grid header files

// The validation types as used by GX_IDS_UA_DATEVALIDMODE

GX_DTVALIDMODE_NONE_T("0")// No validation is required

GX_DTVALIDMODE_TIME_T("1")// Validation of time fields only

GX_DTVALIDMODE_DATE_T("2")// Validation of date fields only

GX_DTVALIDMODE_DATETIME_T("3")// Validation of date & time fields

·GX_IDS_UA_DATEFORMATTYPE: This attribute sets the format for the CGXDateTimeCtrl. The format essentially specifies the layout of the various gadgets in the control. For example a format of say, CGXBDateTimeCtrl::Time would set up the gadgets in the control in such a way that time is displayed in the control.

The following are the predefined constants for the formats:

GX_DTFORMAT_TIME_T("0")// Locale time format

GX_DTFORMAT_SHORTDATE_T("1")// Locale short date format

GX_DTFORMAT_LONGDATE_T("2")// Locale long date format

GX_DTFORMAT_CUSTOM_T("3")// A user supplied date/time format string

CGXDateTimeCtrl also supports custom formats.

Here is how custom formats are specified:

hHours

hh Hours with leading zero

H Same as h, but 24-hour format

HH Same as hh, but 24-hour format

m Minutes

mm Minutes with leading zero

s Seconds

ss Seconds with leading zero

t Abbreviated AM/PM designator

tt Full AM/PM designator

dNumeric day

ddNumeric day with leading zero

dddAbbreviated day name

ddddFull day name

MMonth

MMMonth with leading zero

MMMAbbreviated month

MMMM Full month name

YYear without century

yyYear with leading zero, without century

yyyyYear including century

ggEra (ignored)

'text' Quoted text passed straight through

Any combination of these can be coded into the user attribute, GX_IDS_UA_CUSTOMFORMAT to give a totally custom appearance to the CGXDateTimeCtrl.

·GX_IDS_UA_FASTINPUT: This attribute sets the fast input mode for the datetime control. If this attribute is equal to1, fast input will be enabled. With Fast Input, the input foccus will automatically move to the next gadget while the user is entering numbers.

The following are the predefined constants for the formats:

See Also

 CGXAbstractControlFactory::RegisterAllUserAttributes  CGXStylesMap::AddUserAttribute

CGXDateTimeCtrl

 Class Overview |  Class Members