ComponentOne True DBGrid for WinForms
Displaying the Date and Time in a Column
True DBGrid for WinForms Task-Based Help > Displaying the Date and Time in a Column

In previous versions of True DBGrid for WinForms, the default behavior in a column with a DataType of DateTime was to display both the date and the time in the column. Currently the default behavior is to display only the date. In the following steps, you'll set the column's NumberFormat property to "g" (which displays the short date and short time according to your current culture's format) for both the data and time to be displayed and you'll disable the DateTimePicker used to edit the date and time at run time.

In the Designer

Complete the following steps to display both the date and the time in the column:

  1. Click the ellipsis button next to the Columns collection in the Properties window to open the C1TrueDBGrid Designer. For information on how to access the C1TrueDBGrid Designer, see Accessing the C1TrueDBGrid Designer.
  2. In the designer's right pane, select the column you wish to change.
  3. In the left pane, select the Column tab to view the column's properties.
  4. In the properties grid, select the drop-down arrow next to the column's NumberFormat property and set it to "g".
  5. Select the drop-down arrow next to the column's EnableDateTimeEditor property and set it to False.
  6. Click OK to save your changes and close the designer.

In Code

Add the following code to the Form_Load event to display both the date and the time in the second column:

To write code in Visual Basic

Visual Basic
Copy Code
Me.C1TrueDBGrid1.Columns(1).EnableDateTimeEditor = False
Me.C1TrueDBGrid1.Columns(1).NumberFormat = "g"

To write code in C#

C#
Copy Code
this.c1TrueDBGrid1.Columns[1].EnableDateTimeEditor = false;
this.c1TrueDBGrid1.Columns[1].NumberFormat = "g";

What You've Accomplished

The selected column displays both the date and the time.