using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.ComponentModel; using FastReport.Utils; using System.Drawing; namespace FastReport.Dialog { /// /// Represents a Windows list view control, which displays a collection of items that can be displayed using one of four different views. /// Wraps the control. /// public partial class ListViewControl : DialogControl { private ListView listView; private string itemCheckedEvent; private string selectedIndexChangedEvent; #region Properties /// /// Occurs when the checked state of an item changes. /// Wraps the event. /// public event ItemCheckedEventHandler ItemChecked; /// /// Occurs when the index of the selected item in the list view control changes. /// Wraps the event. /// public event EventHandler SelectedIndexChanged; /// /// Gets an internal ListView. /// [Browsable(false)] public ListView ListView { get { return listView; } } /// /// Gets or sets a value indicating whether a check box appears next to each item in the control. /// Wraps the property. /// [DefaultValue(false)] [Category("Appearance")] public bool CheckBoxes { get { return ListView.CheckBoxes; } set { ListView.CheckBoxes = value; } } /// /// Gets or sets a value indicating whether multiple items can be selected. /// Wraps the property. /// [DefaultValue(true)] [Category("Behavior")] public bool MultiSelect { get { return ListView.MultiSelect; } set { ListView.MultiSelect = value; } } /// /// Gets or sets a value indicating whether items are displayed in groups. /// Wraps the property. /// [DefaultValue(true)] [Category("Behavior")] public bool ShowGroups { get { return ListView.ShowGroups; } set { ListView.ShowGroups = value; } } /// /// Gets or sets how items are displayed in the control. /// Wraps the property. /// [DefaultValue(View.LargeIcon)] [Category("Appearance")] public View View { get { return ListView.View; } set { ListView.View = value; } } /// /// Gets or sets a script method name that will be used to handle the /// event. /// [Category("Events")] public string ItemCheckedEvent { get { return itemCheckedEvent; } set { itemCheckedEvent = value; } } /// /// Gets or sets a script method name that will be used to handle the /// event. /// [Category("Events")] public string SelectedIndexChangedEvent { get { return selectedIndexChangedEvent; } set { selectedIndexChangedEvent = value; } } /// /// Gets the indexes of the currently checked items in the control. /// Wraps the property. /// [Browsable(false)] public ListView.CheckedIndexCollection CheckedIndices { get { return ListView.CheckedIndices; } } /// /// Gets the currently checked items in the control. /// Wraps the property. /// [Browsable(false)] public ListView.CheckedListViewItemCollection CheckedItems { get { return ListView.CheckedItems; } } /// /// Gets the collection of all column headers that appear in the control. /// Wraps the property. /// [Browsable(false)] public ListView.ColumnHeaderCollection Columns { get { return ListView.Columns; } } /// /// Gets the collection of ListViewGroup objects assigned to the control. /// Wraps the property. /// [Browsable(false)] public ListViewGroupCollection Groups { get { return ListView.Groups; } } /// /// Gets a collection containing all items in the control. /// Wraps the property. /// [Browsable(false)] public ListView.ListViewItemCollection Items { get { return ListView.Items; } } /// /// Gets or sets the ImageList to use when displaying items as large icons in the control. /// Wraps the property. /// [Browsable(false)] public ImageList LargeImageList { get { return ListView.LargeImageList; } set { ListView.LargeImageList = value; } } /// /// Gets the indexes of the selected items in the control. /// Wraps the property. /// [Browsable(false)] public ListView.SelectedIndexCollection SelectedIndices { get { return ListView.SelectedIndices; } } /// /// Gets the items that are selected in the control. /// Wraps the property. /// [Browsable(false)] public ListView.SelectedListViewItemCollection SelectedItems { get { return ListView.SelectedItems; } } /// /// Gets or sets the ImageList to use when displaying items as small icons in the control. /// Wraps the property. /// [Browsable(false)] public ImageList SmallImageList { get { return ListView.SmallImageList; } set { ListView.SmallImageList = value; } } #endregion #region Private Methods private void ListView_ItemChecked(object sender, ItemCheckedEventArgs e) { OnItemChecked(e); } private void ListView_SelectedIndexChanged(object sender, EventArgs e) { OnSelectedIndexChanged(e); } #endregion #region Protected Methods /// protected override void AttachEvents() { base.AttachEvents(); ListView.ItemChecked += new ItemCheckedEventHandler(ListView_ItemChecked); ListView.SelectedIndexChanged += new EventHandler(ListView_SelectedIndexChanged); } /// protected override void DetachEvents() { base.DetachEvents(); ListView.ItemChecked -= new ItemCheckedEventHandler(ListView_ItemChecked); ListView.SelectedIndexChanged -= new EventHandler(ListView_SelectedIndexChanged); } #endregion #region Public Methods /// public override void Serialize(FRWriter writer) { ListViewControl c = writer.DiffObject as ListViewControl; base.Serialize(writer); if (CheckBoxes != c.CheckBoxes) writer.WriteBool("CheckBoxes", CheckBoxes); if (MultiSelect != c.MultiSelect) writer.WriteBool("MultiSelect", MultiSelect); if (ShowGroups != c.ShowGroups) writer.WriteBool("ShowGroups", ShowGroups); if (View != c.View) writer.WriteValue("View", View); } /// /// This method fires the ItemChecked event and the script code connected to the ItemCheckedEvent. /// /// Event data. public virtual void OnItemChecked(ItemCheckedEventArgs e) { if (ItemChecked != null) ItemChecked(this, e); InvokeEvent(ItemCheckedEvent, e); } /// /// This method fires the SelectedIndexChanged event and the script code connected to the SelectedIndexChangedEvent. /// /// Event data. public virtual void OnSelectedIndexChanged(EventArgs e) { if (SelectedIndexChanged != null) SelectedIndexChanged(this, e); InvokeEvent(SelectedIndexChangedEvent, e); } #endregion /// /// Initializes a new instance of the ListViewControl class with default settings. /// public ListViewControl() { listView = new ListView(); Control = listView; ListView.HideSelection = false; } } }