/// <summary>
    /// Sets the checked.
    /// </summary>
    /// <param name="isChecked">if set to <c>true</c> [is checked].</param>
    /// <param name="clb">The CLB.</param>
    private void SetChecked(bool isChecked, CheckedPropertyItem item)
    {
        PropertyInfo info = this.GetPropertyInfo(item.PropertyName);

        if (info.CanWrite)
        {
            info.SetValue(this.DataSource, isChecked, null);
        }
    }
    /// <summary>
    /// Adds the check list box item.
    /// </summary>
    /// <param name="item">The item.</param>
    public void AddCheckListBoxItem(CheckedPropertyItem item)
    {
        PropertyInfo info      = this.GetPropertyInfo(item.PropertyName);
        bool         isChecked = false;

        if (info != null)
        {
            isChecked = (bool)info.GetValue(this.DataSource, null);
        }
        this.checkedListBox.Items.Add(item, isChecked);
    }
 /// <summary>
 /// Handles the ItemCheck event of the CheckedListBox control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.Windows.Forms.ItemCheckEventArgs"/> instance containing the event data.</param>
 private void CheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
 {
     if (BindImmediate)
     {
         CheckedListBox      clb         = sender as CheckedListBox;
         CheckedPropertyItem checkedItem = clb.Items[e.Index] as CheckedPropertyItem;
         this.SetChecked(
             e.NewValue == CheckState.Checked ? true : false,
             checkedItem);
     }
 }
    /// <summary>
    /// Handles the ItemCheck event of the CheckedListBox control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Windows.Forms.ItemCheckEventArgs"/> instance containing the event data.</param>
    private void CheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
    {
        CheckedListBox      clb         = sender as CheckedListBox;
        CheckedPropertyItem checkedItem = clb.Items[e.Index] as CheckedPropertyItem;
        PropertyInfo        info        = this.GetPropertyInfo(checkedItem.PropertyName);

        if (info.CanWrite)
        {
            bool isChecked = e.NewValue == CheckState.Checked ? true : false;
            info.SetValue(this.DataSource, isChecked, null);
        }
    }
 /// <summary>
 /// Commits the changes.
 /// </summary>
 public void CommitChanges()
 {
     if (!this.BindImmediate)
     {
         for (int i = 0; i < this.checkedListBox.Items.Count; i++)
         {
             CheckedPropertyItem checkedItem = this.checkedListBox.Items[i] as CheckedPropertyItem;
             this.SetChecked(this.checkedListBox.GetItemChecked(i), checkedItem);
         }
     }
     else
     {
         throw new InvalidOperationException("You cannot commit changes when bind immediate is on.");
     }
 }