Lines showing parent child relation

3 posts, 1 answers
  1. Yury Babaev
    Yury Babaev avatar
    5 posts
    Member since:
    Feb 2010

    Posted 15 Mar 2012 Link to this post

    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. Answer
    Ivan Petrov
    Admin
    Ivan Petrov avatar
    705 posts

    Posted 19 Mar 2012 Link to this post

    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 >>
  3. Yury Babaev
    Yury Babaev avatar
    5 posts
    Member since:
    Feb 2010

    Posted 20 Mar 2012 Link to this post

    That's exactly what I needed. Thank you.
Back to Top