using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace MatrixControl
{
public partial class M42CheckBoxControl : UserControl
{
private static int index = 0;
public M42CheckBoxControl()
{
InitializeComponent();
}
# region Properties
///
/// These are the properties value contains the text string seperated by the seperator
///
private string _value;
public string Value
{
set
{
_value = value;
}
}
///
/// Seperator is also a string by which we will parse the text string.
///
private string _seperator;
public string Seperator
{
set
{
_seperator = value;
}
}
///
/// This is default value means which checkbox will be checked by default.
///
private string _default;
public string Default
{
set
{
_default = value;
}
}
# endregion
#region private
///
/// This event will fire when checkBox will checked or unchecked.
///
///
///
private void checkedListBox1_SelectedValueChanged(object sender, EventArgs e)
{
//Creates an array of strings upto the number of check boxes avaliable in check box list.
string[] checkedItems = new string[M42CheckedListBox.CheckedItems.Count];
foreach (object objchecked in M42CheckedListBox.CheckedItems)
{
checkedItems[M42CheckedListBox.CheckedItems.IndexOf(objchecked)] = objchecked.ToString();
}
//This join method string.Join(_seperator, collectionOfCheckedItems) will give the selected items.
this.Description.Text= string.Join(_seperator, checkedItems);
}
# endregion
#region public
///
/// This check box option is firstly parse all the values and defaults then store iot in check
/// list boxes and text.
///
public void CheckBoxOption()
{
index = 0;
//This is to split through seperator
string[] parseString = _value.Split(_seperator.ToCharArray());
//thisd is to split the defailt value through seperator
string[] defaultString = _default.Split(_seperator.ToCharArray());
//this default description string array is just to store all the default values.
string[] defaultDescription = new string[defaultString.Length];
//This for loop is just to find the index of default value and create the check boxes.
if (_value != string.Empty)
{
foreach (string value in parseString)
{
if (M42CheckedListBox.Items.Contains(value))
{
}
else
{
M42CheckedListBox.Items.Add(value);
}
}
foreach (string defaultValue in defaultString)
{
if (M42CheckedListBox.Items.Contains(defaultValue))
{
M42CheckedListBox.SetItemCheckState(M42CheckedListBox.Items.IndexOf(defaultValue), CheckState.Checked);
defaultDescription[index++] = (defaultValue);
}
this.Description.Text = string.Join(_seperator, defaultDescription);
}
}
}
# endregion
}
}
0 comments:
Post a Comment