Flexible TreeView Flexible TreeView


Support & Community

NodeDateTime node control

Previous Table of Contents Next

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 with the DateTime type to the node class, and then set this member`s name in the NodeDateTime node control property.
Please note that 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);


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 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.

Please, 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);

{0:dd.MM.yy hh:mm:ss}’ pattern defined in this sample contains these 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 that 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.


Edit

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

Previous Top Next


Last news
Bookmark and Share
Use Flexible TreeView in WPF project
Sunday, 18 December 2011

Do you have a WPF project and want to use Flexible TreeView there? No problem!

Flexible TreeView v3.4
Friday, 16 December 2011

Flexible TreeView v3.4 maintenance release has been released.

Flexible TreeView v3.3
Friday, 23 September 2011

Flexible TreeView v3.3 maintenance release has been released. Separate assemblies for .NET 2.0, 4.0 and 4.0 Client Profile, HTML markup extension, etc.

Latest release

Version:
Release date:
3.4
Dec 16, 2011


Copyright © 2006-2012 ARMSoft. All rights reserved.