The WinForms Data Grid allows you to specify custom styles for group rows and corresponding indents by handling the GridView.GroupLevelStyle event. This example demonstrates how to implement this feature in the WinForms TreeList control.
-
Use the TreeList.ViewInfo property to obtain information required to calculate bounds of group indents.
-
Use the
TreeListViewInfo.RC.LevelWidth
property to get the width of a group indent to properly divide the node indent into groups. -
Handle the TreeList.CustomDrawNodeIndent event to calculate group indent bounds.
private void OnTreeListCustomDrawNodeIndent(object sender, CustomDrawNodeIndentEventArgs e) { e.Handled = true; TreeList tree = (TreeList)sender; Dictionary<int, Rectangle> groupLevelIndentRects = new Dictionary<int, Rectangle>(); CalcGroupLevelIndentRects(tree.ViewInfo, e.Node, e.Bounds, groupLevelIndentRects); foreach (KeyValuePair<int, Rectangle> kvp in groupLevelIndentRects) e.Cache.FillRectangle(e.Cache.GetSolidBrush(GetColorByLevel(kvp.Key)), kvp.Value); if (e.Node.ParentNode == null) { Pen linePen = e.Cache.GetPen(tree.ViewInfo.PaintAppearance.HorzLine.BackColor); e.Cache.DrawLine(linePen, e.Bounds.Location, new Point(e.Bounds.Right, e.Bounds.Y)); } }
-
Set the TreeList.TreeLineStyle property to
LineStyle.None
to hide tree lines.
(you will be redirected to DevExpress.com to submit your response)