ListViewControl.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Windows.Forms;
  5. using System.ComponentModel;
  6. using FastReport.Utils;
  7. using System.Drawing;
  8. namespace FastReport.Dialog
  9. {
  10. /// <summary>
  11. /// Represents a Windows list view control, which displays a collection of items that can be displayed using one of four different views.
  12. /// Wraps the <see cref="System.Windows.Forms.ListView"/> control.
  13. /// </summary>
  14. public partial class ListViewControl : DialogControl
  15. {
  16. private ListView listView;
  17. private string itemCheckedEvent;
  18. private string selectedIndexChangedEvent;
  19. #region Properties
  20. /// <summary>
  21. /// Occurs when the checked state of an item changes.
  22. /// Wraps the <see cref="System.Windows.Forms.ListView.ItemChecked"/> event.
  23. /// </summary>
  24. public event ItemCheckedEventHandler ItemChecked;
  25. /// <summary>
  26. /// Occurs when the index of the selected item in the list view control changes.
  27. /// Wraps the <see cref="System.Windows.Forms.ListView.SelectedIndexChanged"/> event.
  28. /// </summary>
  29. public event EventHandler SelectedIndexChanged;
  30. /// <summary>
  31. /// Gets an internal <b>ListView</b>.
  32. /// </summary>
  33. [Browsable(false)]
  34. public ListView ListView
  35. {
  36. get { return listView; }
  37. }
  38. /// <summary>
  39. /// Gets or sets a value indicating whether a check box appears next to each item in the control.
  40. /// Wraps the <see cref="System.Windows.Forms.ListView.CheckBoxes"/> property.
  41. /// </summary>
  42. [DefaultValue(false)]
  43. [Category("Appearance")]
  44. public bool CheckBoxes
  45. {
  46. get { return ListView.CheckBoxes; }
  47. set { ListView.CheckBoxes = value; }
  48. }
  49. /// <summary>
  50. /// Gets or sets a value indicating whether multiple items can be selected.
  51. /// Wraps the <see cref="System.Windows.Forms.ListView.MultiSelect"/> property.
  52. /// </summary>
  53. [DefaultValue(true)]
  54. [Category("Behavior")]
  55. public bool MultiSelect
  56. {
  57. get { return ListView.MultiSelect; }
  58. set { ListView.MultiSelect = value; }
  59. }
  60. /// <summary>
  61. /// Gets or sets a value indicating whether items are displayed in groups.
  62. /// Wraps the <see cref="System.Windows.Forms.ListView.ShowGroups"/> property.
  63. /// </summary>
  64. [DefaultValue(true)]
  65. [Category("Behavior")]
  66. public bool ShowGroups
  67. {
  68. get { return ListView.ShowGroups; }
  69. set { ListView.ShowGroups = value; }
  70. }
  71. /// <summary>
  72. /// Gets or sets how items are displayed in the control.
  73. /// Wraps the <see cref="System.Windows.Forms.ListView.View"/> property.
  74. /// </summary>
  75. [DefaultValue(View.LargeIcon)]
  76. [Category("Appearance")]
  77. public View View
  78. {
  79. get { return ListView.View; }
  80. set { ListView.View = value; }
  81. }
  82. /// <summary>
  83. /// Gets or sets a script method name that will be used to handle the
  84. /// <see cref="ItemChecked"/> event.
  85. /// </summary>
  86. [Category("Events")]
  87. public string ItemCheckedEvent
  88. {
  89. get { return itemCheckedEvent; }
  90. set { itemCheckedEvent = value; }
  91. }
  92. /// <summary>
  93. /// Gets or sets a script method name that will be used to handle the
  94. /// <see cref="SelectedIndexChanged"/> event.
  95. /// </summary>
  96. [Category("Events")]
  97. public string SelectedIndexChangedEvent
  98. {
  99. get { return selectedIndexChangedEvent; }
  100. set { selectedIndexChangedEvent = value; }
  101. }
  102. /// <summary>
  103. /// Gets the indexes of the currently checked items in the control.
  104. /// Wraps the <see cref="System.Windows.Forms.ListView.CheckedIndices"/> property.
  105. /// </summary>
  106. [Browsable(false)]
  107. public ListView.CheckedIndexCollection CheckedIndices
  108. {
  109. get { return ListView.CheckedIndices; }
  110. }
  111. /// <summary>
  112. /// Gets the currently checked items in the control.
  113. /// Wraps the <see cref="System.Windows.Forms.ListView.CheckedItems"/> property.
  114. /// </summary>
  115. [Browsable(false)]
  116. public ListView.CheckedListViewItemCollection CheckedItems
  117. {
  118. get { return ListView.CheckedItems; }
  119. }
  120. /// <summary>
  121. /// Gets the collection of all column headers that appear in the control.
  122. /// Wraps the <see cref="System.Windows.Forms.ListView.Columns"/> property.
  123. /// </summary>
  124. [Browsable(false)]
  125. public ListView.ColumnHeaderCollection Columns
  126. {
  127. get { return ListView.Columns; }
  128. }
  129. /// <summary>
  130. /// Gets the collection of ListViewGroup objects assigned to the control.
  131. /// Wraps the <see cref="System.Windows.Forms.ListView.Groups"/> property.
  132. /// </summary>
  133. [Browsable(false)]
  134. public ListViewGroupCollection Groups
  135. {
  136. get { return ListView.Groups; }
  137. }
  138. /// <summary>
  139. /// Gets a collection containing all items in the control.
  140. /// Wraps the <see cref="System.Windows.Forms.ListView.Items"/> property.
  141. /// </summary>
  142. [Browsable(false)]
  143. public ListView.ListViewItemCollection Items
  144. {
  145. get { return ListView.Items; }
  146. }
  147. /// <summary>
  148. /// Gets or sets the ImageList to use when displaying items as large icons in the control.
  149. /// Wraps the <see cref="System.Windows.Forms.ListView.LargeImageList"/> property.
  150. /// </summary>
  151. [Browsable(false)]
  152. public ImageList LargeImageList
  153. {
  154. get { return ListView.LargeImageList; }
  155. set { ListView.LargeImageList = value; }
  156. }
  157. /// <summary>
  158. /// Gets the indexes of the selected items in the control.
  159. /// Wraps the <see cref="System.Windows.Forms.ListView.SelectedIndices"/> property.
  160. /// </summary>
  161. [Browsable(false)]
  162. public ListView.SelectedIndexCollection SelectedIndices
  163. {
  164. get { return ListView.SelectedIndices; }
  165. }
  166. /// <summary>
  167. /// Gets the items that are selected in the control.
  168. /// Wraps the <see cref="System.Windows.Forms.ListView.SelectedItems"/> property.
  169. /// </summary>
  170. [Browsable(false)]
  171. public ListView.SelectedListViewItemCollection SelectedItems
  172. {
  173. get { return ListView.SelectedItems; }
  174. }
  175. /// <summary>
  176. /// Gets or sets the ImageList to use when displaying items as small icons in the control.
  177. /// Wraps the <see cref="System.Windows.Forms.ListView.SmallImageList"/> property.
  178. /// </summary>
  179. [Browsable(false)]
  180. public ImageList SmallImageList
  181. {
  182. get { return ListView.SmallImageList; }
  183. set { ListView.SmallImageList = value; }
  184. }
  185. #endregion
  186. #region Private Methods
  187. private void ListView_ItemChecked(object sender, ItemCheckedEventArgs e)
  188. {
  189. OnItemChecked(e);
  190. }
  191. private void ListView_SelectedIndexChanged(object sender, EventArgs e)
  192. {
  193. OnSelectedIndexChanged(e);
  194. }
  195. #endregion
  196. #region Protected Methods
  197. /// <inheritdoc/>
  198. protected override void AttachEvents()
  199. {
  200. base.AttachEvents();
  201. ListView.ItemChecked += new ItemCheckedEventHandler(ListView_ItemChecked);
  202. ListView.SelectedIndexChanged += new EventHandler(ListView_SelectedIndexChanged);
  203. }
  204. /// <inheritdoc/>
  205. protected override void DetachEvents()
  206. {
  207. base.DetachEvents();
  208. ListView.ItemChecked -= new ItemCheckedEventHandler(ListView_ItemChecked);
  209. ListView.SelectedIndexChanged -= new EventHandler(ListView_SelectedIndexChanged);
  210. }
  211. #endregion
  212. #region Public Methods
  213. /// <inheritdoc/>
  214. public override void Serialize(FRWriter writer)
  215. {
  216. ListViewControl c = writer.DiffObject as ListViewControl;
  217. base.Serialize(writer);
  218. if (CheckBoxes != c.CheckBoxes)
  219. writer.WriteBool("CheckBoxes", CheckBoxes);
  220. if (MultiSelect != c.MultiSelect)
  221. writer.WriteBool("MultiSelect", MultiSelect);
  222. if (ShowGroups != c.ShowGroups)
  223. writer.WriteBool("ShowGroups", ShowGroups);
  224. if (View != c.View)
  225. writer.WriteValue("View", View);
  226. }
  227. /// <summary>
  228. /// This method fires the <b>ItemChecked</b> event and the script code connected to the <b>ItemCheckedEvent</b>.
  229. /// </summary>
  230. /// <param name="e">Event data.</param>
  231. public virtual void OnItemChecked(ItemCheckedEventArgs e)
  232. {
  233. if (ItemChecked != null)
  234. ItemChecked(this, e);
  235. InvokeEvent(ItemCheckedEvent, e);
  236. }
  237. /// <summary>
  238. /// This method fires the <b>SelectedIndexChanged</b> event and the script code connected to the <b>SelectedIndexChangedEvent</b>.
  239. /// </summary>
  240. /// <param name="e">Event data.</param>
  241. public virtual void OnSelectedIndexChanged(EventArgs e)
  242. {
  243. if (SelectedIndexChanged != null)
  244. SelectedIndexChanged(this, e);
  245. InvokeEvent(SelectedIndexChangedEvent, e);
  246. }
  247. #endregion
  248. /// <summary>
  249. /// Initializes a new instance of the <b>ListViewControl</b> class with default settings.
  250. /// </summary>
  251. public ListViewControl()
  252. {
  253. listView = new ListView();
  254. Control = listView;
  255. ListView.HideSelection = false;
  256. }
  257. }
  258. }