I wish to have checkbox to the root nodes and not the child nodes of the Treeview control.
- [x]Pie Chart report
- Sales report
- Sales Projection report
- Linear Sales report
- [x]Surface Chart report
- Sales report
- Sales Projection report
- Linear Sales report
- [x]Caligraph report
- Sales report
- Sales Projection report
- Linear Sales report
To achieve this I have done change in my regular treeview control
tvreport is the Treeview Control
this.tvreport.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(tvreport_DrawNode);
this.tvreport.ShowLines = true;
this.tvreport.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawAll;
private void tvreport_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
if (IsContactNode(e.Node))
{
Color backColor, foreColor;
if ((e.State & TreeNodeStates.Selected) == TreeNodeStates.Selected)
{
backColor = SystemColors.Highlight;
foreColor = SystemColors.HighlightText;
}
if ((e.State & TreeNodeStates.Hot) == TreeNodeStates.Hot)
{
backColor = SystemColors.HotTrack;
foreColor = SystemColors.HighlightText;
}
else
{
backColor = e.Node.BackColor;
foreColor = e.Node.ForeColor;
}
Rectangle newBounds = e.Node.Bounds;
newBounds.X = 60;
using (SolidBrush brush = new SolidBrush(backColor))
{
e.Graphics.FillRectangle(brush, e.Node.Bounds);
}
TextRenderer.DrawText(e.Graphics, e.Node.Text, this.tvreport.Font, e.Node.Bounds, foreColor, backColor);
if ((e.State & TreeNodeStates.Focused) == TreeNodeStates.Focused)
{
ControlPaint.DrawFocusRectangle(e.Graphics, e.Node.Bounds, foreColor, backColor);
}
e.DrawDefault = false;
}
else
{
e.DrawDefault = true;
tvContactList1.ShowRootLines = true;
tvContactList1.ShowLines = true;
}
}
private bool IsContactNode(TreeNode node)
{
return node.Parent != null;
}
After running the code have found that the root node is showing checkbox and childnodes is without checkbox [that is what I wish to have].
But the problem is the "Lines" that shows the hierarchy got disappeared. Now I want to populate those LINES. How can this be achieved.