using System;
using System.Collections.Generic;
using System.ComponentModel;
using FastReport.Utils;
using System.Windows.Forms;
using FastReport.Data;
namespace FastReport.Dialog
{
///
/// Displays a ListBox in which a check box is displayed to the left of each item.
/// Wraps the control.
///
public partial class CheckedListBoxControl : ListBoxBaseControl
{
private CheckedListBox checkedListBox;
private string itemCheckEvent;
private Timer timer;
#region Properties
///
/// Occurs after item's check state was changed.
/// Wraps the event.
///
public event ItemCheckEventHandler ItemCheck;
///
/// Gets an internal CheckedListBox.
///
[Browsable(false)]
public CheckedListBox CheckedListBox
{
get { return checkedListBox; }
}
///
/// Gets or sets a value indicating whether the check box should be toggled when an item is selected.
/// Wraps the property.
///
[DefaultValue(false)]
public bool CheckOnClick
{
get { return CheckedListBox.CheckOnClick; }
set { CheckedListBox.CheckOnClick = value; }
}
///
/// Gets the items of the CheckedListBox.
/// Wraps the property.
///
public new CheckedListBox.ObjectCollection Items
{
get { return CheckedListBox.Items; }
}
///
/// Collection of checked indexes in this CheckedListBox.
/// Wraps the property.
///
[Browsable(false)]
public CheckedListBox.CheckedIndexCollection CheckedIndices
{
get { return CheckedListBox.CheckedIndices; }
}
///
/// Collection of checked items in this CheckedListBox.
/// Wraps the property.
///
[Browsable(false)]
public CheckedListBox.CheckedItemCollection CheckedItems
{
get { return CheckedListBox.CheckedItems; }
}
///
public override string ItemsText
{
get { return Converter.IListToString(Items); }
set { Converter.StringToIList(value, Items); }
}
///
/// Gets or sets a script method name that will be used to handle the
/// event.
///
[Category("Events")]
public string ItemCheckEvent
{
get { return itemCheckEvent; }
set { itemCheckEvent = value; }
}
#endregion
#region Private Methods
private void CheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
{
OnItemCheck(e);
}
private void FTimer_Tick(object sender, EventArgs e)
{
timer.Stop();
OnFilterChanged();
}
#endregion
#region Protected Methods
///
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
timer.Dispose();
}
///
protected override void AttachEvents()
{
base.AttachEvents();
CheckedListBox.ItemCheck += new ItemCheckEventHandler(CheckedListBox_ItemCheck);
}
///
protected override void DetachEvents()
{
base.DetachEvents();
CheckedListBox.ItemCheck -= new ItemCheckEventHandler(CheckedListBox_ItemCheck);
}
///
protected override void FillData(DataSourceBase dataSource, Column column)
{
Items.Clear();
Items.AddRange(GetListOfData(dataSource, column));
if (Items.Count > 0)
SelectedIndex = 0;
}
///
protected override object GetValue()
{
List list = new List();
foreach (object item in CheckedItems)
{
list.Add((string)item);
}
return list.ToArray();
}
#endregion
#region Public Methods
///
public override void Serialize(FRWriter writer)
{
CheckedListBoxControl c = writer.DiffObject as CheckedListBoxControl;
base.Serialize(writer);
if (CheckOnClick != c.CheckOnClick)
writer.WriteBool("CheckOnClick", CheckOnClick);
if (ItemCheckEvent != c.ItemCheckEvent)
writer.WriteStr("ItemCheckEvent", ItemCheckEvent);
}
///
/// This method fires the ItemCheck event and the script code connected to the ItemCheckEvent.
///
/// Event data.
public virtual void OnItemCheck(ItemCheckEventArgs e)
{
if (ItemCheck != null)
ItemCheck(this, e);
InvokeEvent(ItemCheckEvent, e);
timer.Start();
}
#endregion
///
/// Initializes a new instance of the CheckedListBoxControl class with default settings.
///
public CheckedListBoxControl()
{
checkedListBox = new CheckedListBox();
Control = checkedListBox;
CheckedListBox.IntegralHeight = false;
timer = new Timer();
timer.Interval = 50;
timer.Tick += new EventHandler(FTimer_Tick);
}
}
}