Skip to content

NodeDateTime

NodeDateTime node control allows you to display and edit the date and/or time data in the treeview.

Data binding#

To bind the NodeDateTime node control to a node, you need to add a member of DateTime or Nullable<DateTime> type to the node class, and then specify this member's name in the DataFieldName node control property.

Note

NodeDateTime doesn't pre-fill the DateFieldName property with a default value, so you need to fill it in manually.

Example

// Custom node class with the OrderDate member for binding to the node control.
class OrderNode : Node
{
    public DateTime OrderDate { get; set; }
}

// NodeDateTime node control usage example.
NodeTextBox tb = new NodeTextBox();
tb.AttachTo(tree);

NodeDateTime dt = new NodeDateTime();
// Bind the NodeDateTime node control.
dt.DataFieldName = "OrderDate";
// Set the bound data formatting to show both date and time.
dt.ShowDate = true;
dt.ShowTime = true;
dt.AttachTo(tree);

// Add a node to show in the treeview.
OrderNode node = new OrderNode();
node.Text = "Order #1";
node.OrderDate = DateTime.Now;
node.AttachTo(tree);
' Custom node class with the OrderDate member for binding to the node control.
Class OrderNode
    Inherits Node
    Public Property OrderDate As DateTime
End Class

' NodeDateTime node control usage example.
Dim tb As New NodeTextBox()
tb.AttachTo(tree)

Dim dt As New NodeDateTime()
' Bind the NodeDateTime node control.
dt.DataFieldName = "OrderDate"
' Set the bound data formatting to show both date and time.
dt.ShowDate = True
dt.ShowTime = True
dt.AttachTo(tree)

' Add a node to show in the treeview.
Dim node As New OrderNode()
node.Text = "Order #1"
node.OrderDate = DateTime.Now
node.AttachTo(tree)

Nullable<DateTime> data type support#

NodeDateTime, apart from DateTime type, also supports Nullable<DateTime> data type.

When the bound value is null and the user tries to edit it, the EditorRepository.DateTimeEditor.MinDate treeview property value will be used instead to initialize the editor.

Quick formatting#

Besides the flexible custom formatting described below, NodeDateTime node control allows you to quickly define what portion of the bound data you need to display - date and/or time. To do that, enable the ShowDate node control property to display the date portion of the bound data, and/or ShowTime to display the time portion.

NodeDateTime node control uses these standard date/time format patterns when the quick format is enabled:

  • "g" (shows date and time) - when both ShowDate and ShowTime properties are enabled.
  • "d" (shows date only) - when the ShowDate property is enabled.
  • "t" (shows time only) - when the ShowTime property is enabled.

Read the Standard Date and Time Format Strings topic for details.

Custom formatting#

Besides the quick formatting options described above, NodeDateTime node control allows you to define flexible date/time custom formatting as you need. To do that, enable the DisplayFormat.Enabled node control property and then set a custom format pattern in the DisplayFormat.FormatText node control property using the custom date and time format string described in the Custom Date and Time Format Strings topic.

Example

// Custom node class with the OrderDate member for binding to the node control.
class OrderNode : Node
{
    public DateTime OrderDate { get; set; }
}

// NodeDateTime node control usage example.
NodeTextBox tb = new NodeTextBox();
tb.AttachTo(tree);

NodeDateTime dt = new NodeDateTime();
// Bind the NodeDateTime node control.
dt.DataFieldName = "OrderDate";
// Enable and set the custom date/time formatting.
dt.DisplayFormat.Enabled = true;
dt.DisplayFormat.FormatText = "{0:dd.MM.yy hh:mm:ss}";
dt.AttachTo(tree);

// Add a node to show in the treeview.
OrderNode node = new OrderNode();
node.Text = "Order #1";
node.OrderDate = DateTime.Now;
node.AttachTo(tree);
' Custom node class with the OrderDate member for binding to the node control.
Class OrderNode
    Inherits Node
    Public Property OrderDate As DateTime
End Class

' NodeDateTime node control usage example.
Dim tb As New NodeTextBox()
tb.AttachTo(tree)

Dim dt As New NodeDateTime()
' Bind the NodeDateTime node control.
dt.DataFieldName = "OrderDate"
' Enable and set the custom date/time formatting.
dt.DisplayFormat.Enabled = True
dt.DisplayFormat.FormatText = "{0:dd.MM.yy hh:mm:ss}"
dt.AttachTo(tree)

' Add a node to show in the treeview.
Dim node As New OrderNode()
node.Text = "Order #1"
node.OrderDate = DateTime.Now
node.AttachTo(tree)

The '{0:dd.MM.yy hh:mm:ss}' pattern specified in the example contains the following parts:

  • 0: - the node control bound data placeholder.
  • dd.MM.yy - displays the date in the format <day>.<month>.<year>.
  • hh:mm:ss - displays the time in the format <hour>.<minutes>.<seconds>.

Note

The custom format cannot be applied to the editor control using the DisplayFormat property. Instead, you need to subscribe to the NodeEditorShown treeview event, cast the supplied editor control to the DateTimePicker type and set the DateTimePicker's CustomFormat property to a format you need.

Editing#

NodeDateTime node control allows the user to edit the bound data using a dropdown calendar. To do that, enable the Editable node control property.

The selected date should be between the EditorRepository.DateTimeEditor.MinDate and EditorRepository.DateTimeEditor.MaxDate treeview properties range.

PlaceholderText#

If NodeDateTime is bound to a Nullable<DateTime> property and it has NULL value, an empty string is displayed in the node. To improve user experience and tell your user what you expect from them, some placeholder text could be displayed instead of that empty string. To define the placeholder text, assign it to the PlaceholderText string property.