TreeViewControl.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. using System.Windows.Forms;
  2. using System.ComponentModel;
  3. using FastReport.Utils;
  4. namespace FastReport.Dialog
  5. {
  6. /// <summary>
  7. /// Displays a hierarchical collection of labeled items, each represented by a TreeNode.
  8. /// Wraps the <see cref="System.Windows.Forms.TreeView"/> control.
  9. /// </summary>
  10. public partial class TreeViewControl : DialogControl
  11. {
  12. private TreeView treeView;
  13. private string afterSelectEvent;
  14. #region Properties
  15. /// <summary>
  16. /// Occurs after the tree node is selected.
  17. /// Wraps the <see cref="System.Windows.Forms.TreeView.AfterSelect"/> event.
  18. /// </summary>
  19. public event TreeViewEventHandler AfterSelect;
  20. /// <summary>
  21. /// Gets an internal <b>TreeView</b>.
  22. /// </summary>
  23. [Browsable(false)]
  24. public TreeView TreeView
  25. {
  26. get { return treeView; }
  27. }
  28. /// <summary>
  29. /// Gets or sets a value indicating whether check boxes are displayed next to the tree nodes in the tree view control.
  30. /// Wraps the <see cref="System.Windows.Forms.TreeView.CheckBoxes"/> property.
  31. /// </summary>
  32. [DefaultValue(false)]
  33. [Category("Appearance")]
  34. public bool CheckBoxes
  35. {
  36. get { return TreeView.CheckBoxes; }
  37. set { TreeView.CheckBoxes = value; }
  38. }
  39. /// <summary>
  40. /// Gets or sets a value indicating whether lines are drawn between tree nodes in the tree view control.
  41. /// Wraps the <see cref="System.Windows.Forms.TreeView.ShowLines"/> property.
  42. /// </summary>
  43. [DefaultValue(true)]
  44. [Category("Behavior")]
  45. public bool ShowLines
  46. {
  47. get { return TreeView.ShowLines; }
  48. set { TreeView.ShowLines = value; }
  49. }
  50. /// <summary>
  51. /// Gets or sets a value indicating whether lines are drawn between the tree nodes that are at the root of the tree view.
  52. /// Wraps the <see cref="System.Windows.Forms.TreeView.ShowRootLines"/> property.
  53. /// </summary>
  54. [DefaultValue(true)]
  55. [Category("Behavior")]
  56. public bool ShowRootLines
  57. {
  58. get { return TreeView.ShowRootLines; }
  59. set { TreeView.ShowRootLines = value; }
  60. }
  61. /// <summary>
  62. /// Gets or sets the <b>ImageList</b> that contains the <b>Image</b> objects used by the tree nodes.
  63. /// Wraps the <see cref="System.Windows.Forms.TreeView.ImageList"/> property.
  64. /// </summary>
  65. [Browsable(false)]
  66. public ImageList ImageList
  67. {
  68. get { return TreeView.ImageList; }
  69. set { TreeView.ImageList = value; }
  70. }
  71. /// <summary>
  72. /// Gets the collection of tree nodes that are assigned to the tree view control.
  73. /// Wraps the <see cref="System.Windows.Forms.TreeView.Nodes"/> property.
  74. /// </summary>
  75. [Browsable(false)]
  76. public TreeNodeCollection Nodes
  77. {
  78. get { return TreeView.Nodes; }
  79. }
  80. /// <summary>
  81. /// Gets or sets the tree node that is currently selected in the tree view control.
  82. /// Wraps the <see cref="System.Windows.Forms.TreeView.SelectedNode"/> property.
  83. /// </summary>
  84. [Browsable(false)]
  85. public TreeNode SelectedNode
  86. {
  87. get { return TreeView.SelectedNode; }
  88. set { TreeView.SelectedNode = value; }
  89. }
  90. /// <summary>
  91. /// Gets or sets a script method name that will be used to handle the
  92. /// <see cref="AfterSelect"/> event.
  93. /// </summary>
  94. [Category("Events")]
  95. public string AfterSelectEvent
  96. {
  97. get { return afterSelectEvent; }
  98. set { afterSelectEvent = value; }
  99. }
  100. #endregion
  101. #region Private Methods
  102. private void TreeView_AfterSelect(object sender, TreeViewEventArgs e)
  103. {
  104. OnAfterSelect(e);
  105. }
  106. #endregion
  107. #region Protected Methods
  108. /// <inheritdoc/>
  109. protected override void AttachEvents()
  110. {
  111. base.AttachEvents();
  112. TreeView.AfterSelect += new TreeViewEventHandler(TreeView_AfterSelect);
  113. }
  114. /// <inheritdoc/>
  115. protected override void DetachEvents()
  116. {
  117. base.DetachEvents();
  118. TreeView.AfterSelect -= new TreeViewEventHandler(TreeView_AfterSelect);
  119. }
  120. #endregion
  121. #region Public Methods
  122. /// <inheritdoc/>
  123. public override void Serialize(FRWriter writer)
  124. {
  125. TreeViewControl c = writer.DiffObject as TreeViewControl;
  126. base.Serialize(writer);
  127. if (CheckBoxes != c.CheckBoxes)
  128. writer.WriteBool("CheckBoxes", CheckBoxes);
  129. if (ShowLines != c.ShowLines)
  130. writer.WriteBool("ShowLines", ShowLines);
  131. if (ShowRootLines != c.ShowRootLines)
  132. writer.WriteBool("ShowRootLines", ShowRootLines);
  133. }
  134. /// <summary>
  135. /// This method fires the <b>AfterSelect</b> event and the script code connected to the <b>AfterSelectEvent</b>.
  136. /// </summary>
  137. /// <param name="e">Event data.</param>
  138. public virtual void OnAfterSelect(TreeViewEventArgs e)
  139. {
  140. if (AfterSelect != null)
  141. AfterSelect(this, e);
  142. InvokeEvent(AfterSelectEvent, e);
  143. }
  144. #endregion
  145. /// <summary>
  146. /// Initializes a new instance of the <see cref="TreeViewControl"/> class with default settings.
  147. /// </summary>
  148. public TreeViewControl()
  149. {
  150. treeView = new TreeView();
  151. Control = treeView;
  152. TreeView.HideSelection = false;
  153. }
  154. }
  155. }