Use these methods to customize the node control text format and appearance.
DisplayFormat
All text node controls display bound data as text using the ToString method, but this is not useful in cases, when you need to customize the text appearance. To change node control`s output text format, use the DisplayFormat property. To do that, enable the Enabled property and provide a text format in the FormatText property. After that, bound data will be displayed using the String.Format method, so FormatText`s format is identical to the String.Format method`s formatting rules. The String.Format method will be called with one parameter, so to insert a data value into the output text, use {0} placeholder in your format. For instance, to display a number with two decimal digits, use this code:
// Custom node class.class NodeEx : Node
{publicdecimal Salary;}
NodeTextBox tb =new NodeTextBox();
tb.AttachTo(tree);
NodeNumeric num =new NodeNumeric();
num.DataFieldName="Salary";
num.DisplayFormat.Enabled= true;// force to show bound numbers with two decimal points.
num.DisplayFormat.FormatText="{0:N2}";
num.AttachTo(tree);
NodeEx node =new NodeEx();
node.Text="John Smith";
node.Salary= 5000.6786M;
node.AttachTo(tree);
Note that your bound data would not be changed when text formatting is enabled and they will appear unformatted in the edit control;
You may exclude the data placeholder ({0}) and show a text that`s not bound to your node control.
NodeControlFormatValue event
The DisplayFormat node control property is useful when you want to apply a static custom text format. Also, Flexible TreeView provides the possibility to dynamically format the node control`s text. To do that, use the NodeControlFormatValue treeview event as shown below. Note that the NodeControlFormatValue event will be raised only when custom formatting is disabled (DisplayFormat.Enabled=false).
Example:
// We have the NodeNumeric node control to display a file size and want to display ‘Kb’ when the file size is greater than 1024.
NodeNumeric num =new NodeNumeric();// 1. Disable custom formatting for the node control. Note that it is disabled by default!
Num.DisplayFormat.Enabled= false;// 2. Subscribe to the NodeControlFormatValue treeview event.
tree.NodeControlFormatValue+= tree_NodeControlFormatValue;// 3. Event handler.void tree_NodeControlFormatValue(FlexibleTreeView pTreeview, FormatValueEventArgs pArgs){// provide the custom formatting only for our node control.if(pArgs.NodeControl== num){decimal val =(decimal)pArgs.Value;if(val >1024){// format the specified value. This text will be displayed in the node control.
pArgs.FormattedValue=string.Format("{0} Kb.", val/1024);}}}
Flexible TreeView v2.6 has been released with Visual Studio 2010 support, new NodeDateTime node control, data access great speed increase and much more.