This is a migrated thread and some comments may be shown as answers.

Lines showing parent child relation

2 Answers 88 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yury Babaev
Top achievements
Rank 1
Yury Babaev asked on 15 Mar 2012, 08:55 AM
Hello,

is it possible to show lines that mark parent-child relation in self-reference grid, like it's done in RadTreeView by setting ShowLines property to true?

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Petrov
Telerik team
answered on 19 Mar 2012, 10:36 AM
Hi Yury,

Thank you for writing.

You can show the lines by setting the RadGridView.TableElement.ShowSelfReferenceLines property to true. After that you can control the color and DashStyle of the lines using the ViewCellFormatting event of the RadGridView. Here is a code snippet which demonstrates how to do this:
private DashStyle lineStyle = DashStyle.Dot;
private Color lineColor = Color.Black;
 
private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    if (!(e.Row is GridViewDataRowInfo))
    {
        return;
    }
 
    GridDataCellElement cell = e.CellElement as GridDataCellElement;
    if (!(cell != null && cell.SelfReferenceLayout != null))
    {
        return;
    }
 
    foreach (RadElement element in cell.SelfReferenceLayout.StackLayoutElement.Children)
    {
        GridLinkItem linkItem = element as GridLinkItem;
        if (linkItem != null)
        {
            linkItem.LineStyle = lineStyle;
            linkItem.ForeColor = lineColor;
        }
        GridExpanderItem expanderItem = element as GridExpanderItem;
        if (expanderItem != null)
        {
            expanderItem.LinkLineStyle = lineStyle;
            expanderItem.LinkLineColor = lineColor;
        }
    }
}

I hope this will be useful for you.

Kind regards,
Ivan Petrov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Yury Babaev
Top achievements
Rank 1
answered on 20 Mar 2012, 08:47 AM
That's exactly what I needed. Thank you.
Tags
GridView
Asked by
Yury Babaev
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Yury Babaev
Top achievements
Rank 1
Share this question
or