Well you could build a TreeView control from scratch (there are several examples available including here on CodeProject).
One "trick" I've just used is as follows...
Create 3 images - a blank "box", a ticked (checked) box, and a (small) blank image.
Add these to an ImageList control and set your TreeView's ImageList property to this ImageList control.
When populating your TreeView set the
SelectedImageIndex
and
ImageIndex
values to the index of the blank image (2 in my case), and the equivalent properties of the child nodes to one of the checked or unchecked images - NB both the same value.
For example I populated my sample like this
for (int i = 0; i < 10; i++)
{
this.treeView1.CheckBoxes = false;
TreeNode tn = this.treeView1.Nodes.Add(i.ToString());
tn.ImageIndex = tBlank;
tn.SelectedImageIndex = tblank;
for (int j = 0; j < 5; j++)
{
tn = this.treeView1.Nodes[i].Nodes.Add(i.ToString() + ":" + j.ToString());
tn.ImageIndex = tChecked;
tn.SelectedImageIndex = tChecked;
}
}
Now you need to handle the check/uncheck yourself ... for example
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
TreeNode tn = e.Node;
if (tn.Level != 0)
{
tn.SelectedImageIndex = (tn.SelectedImageIndex == tUnChecked) ? tChecked : tUnChecked;
tn.ImageIndex = tn.SelectedImageIndex;
}
I've already defined
const int tblank = 2;
const int tChecked = 1;
const int tUnChecked = 0;
Note that you can't use the
Checked
property of the node now, you would need something like
if (this.treeView1.Nodes[2].Nodes[1].ImageIndex == tChecked)
{
}
else
{
}