Hi PRA,
Please refer below sample.
In this sample i used comboBox, checkbox and toolscript control.
I have created this sample by using below link, so refere below link.
https://www.codeproject.com/Articles/18929/An-OwnerDraw-ComboBox-with-CheckBoxes-in-the-Drop
Form Design
Code
Form1.cs
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
checkComboBox1.Items.Add(new CheckComboBox.CheckComboBoxItem("Mudassar", true));
checkComboBox1.Items.Add(new CheckComboBox.CheckComboBoxItem("Ahmad", true));
checkComboBox1.Items.Add(new CheckComboBox.CheckComboBoxItem("Khan", true));
checkBox1.Visible = false;
checkBox2.Visible = false;
checkBox3.Visible = false;
this.checkComboBox1.CheckStateChanged += new System.EventHandler(this.checkComboBox1_CheckStateChanged);
}
private void checkComboBox1_CheckStateChanged(object sender, EventArgs e)
{
if (sender is CheckComboBox.CheckComboBoxItem)
{
CheckComboBox.CheckComboBoxItem item = (CheckComboBox.CheckComboBoxItem)sender;
switch (item.Text)
{
case "Mudassar":
checkBox1.Checked = item.CheckState;
break;
case "Ahmed":
checkBox2.Checked = item.CheckState;
break;
case "Khan":
checkBox3.Checked = item.CheckState;
break;
}
}
}
}
CheckComboBox.cs
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
namespace CheckComboBox
{
public class CheckComboBoxItem
{
public CheckComboBoxItem(string text, bool initialCheckState)
{
_checkState = initialCheckState;
_text = text;
}
private bool _checkState = false;
public bool CheckState
{
get { return _checkState; }
set { _checkState = value; }
}
private string _text = "";
public string Text
{
get { return _text; }
set { _text = value; }
}
private object _tag = null;
public object Tag
{
get { return _tag; }
set { _tag = value; }
}
public override string ToString()
{
return "Select Options";
}
}
public partial class CheckComboBox : ComboBox
{
public CheckComboBox()
{
this.DrawMode = DrawMode.OwnerDrawFixed;
this.DrawItem += new DrawItemEventHandler(CheckComboBox_DrawItem);
this.SelectedIndexChanged += new EventHandler(CheckComboBox_SelectedIndexChanged);
SelectedText = "Select Options";
}
void CheckComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
CheckComboBoxItem item = (CheckComboBoxItem)SelectedItem;
item.CheckState = !item.CheckState;
if (CheckStateChanged != null)
CheckStateChanged(item, e);
}
void CheckComboBox_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index == -1)
{
return;
}
if (!(Items[e.Index] is CheckComboBoxItem))
{
e.Graphics.DrawString(
Items[e.Index].ToString(),
this.Font,
Brushes.Black,
new Point(e.Bounds.X, e.Bounds.Y));
return;
}
CheckComboBoxItem box = (CheckComboBoxItem)Items[e.Index];
CheckBoxRenderer.RenderMatchingApplicationState = true;
CheckBoxRenderer.DrawCheckBox(
e.Graphics,
new Point(e.Bounds.X, e.Bounds.Y),
e.Bounds,
box.Text,
this.Font,
(e.State & DrawItemState.Focus) == 0,
box.CheckState ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal);
}
public event EventHandler CheckStateChanged;
}
}
Screenshot