Change Parent Row BorderColor when Child Rows are expanded

3 posts, 1 answers
  1. christian
    christian avatar
    4 posts
    Member since:
    Jun 2015

    Posted 06 Nov 2015 Link to this post

    Hi Telerik,

     I use the RowFormatting Event to change the bordel color of the parentrow when childrows are expanded, here's my code :

     

    private void GridEmployeRenard_RowFormatting(object sender, Telerik.WinControls.UI.RowFormattingEventArgs e)
           {
               if (e.RowElement.RowInfo.IsExpanded)
               {
                   e.RowElement.BorderColor = RowExpandedColor; // RowExpandedColor is set above in the code
               }
               else
               {
                   e.RowElement.ResetValue(Telerik.WinControls.UI.LightVisualElement.BorderColorProperty, ValueResetFlags.Local);
               }
           }

    However when the row losts focus, the bordercolor is reset.
    I need the rowBorderColor keeps the RowExpandedColor value until the row is collapsed by the user.

    Any idea to do that please ?

     

    Regards.

  2. Answer
    Dess
    Admin
    Dess avatar
    1601 posts

    Posted 11 Nov 2015 Link to this post

    Hello Christian,

    Thank you for writing.

    I am not sure whether you use the ControlDeafult theme, but note that by default cell elements have applied border as well. In order to apply a row border, it is necessary to hide the cell border. Here is a sample code snippet which result is illustrated on the attached screenshot:
    private void radGridView1_RowFormatting(object sender, Telerik.WinControls.UI.RowFormattingEventArgs e)
    {
        if (e.RowElement.RowInfo.IsExpanded)
        {
            e.RowElement.DrawBorder = true;
            e.RowElement.BorderColor = Color.Red;
            e.RowElement.BorderGradientStyle = GradientStyles.Solid;
            e.RowElement.BorderWidth = 2;
        }
        else
        {
            e.RowElement.ResetValue(Telerik.WinControls.UI.LightVisualElement.DrawBorderProperty, ValueResetFlags.Local);
            e.RowElement.ResetValue(Telerik.WinControls.UI.LightVisualElement.BorderColorProperty, ValueResetFlags.Local);
            e.RowElement.ResetValue(Telerik.WinControls.UI.LightVisualElement.BorderGradientStyleProperty, ValueResetFlags.Local);
            e.RowElement.ResetValue(Telerik.WinControls.UI.LightVisualElement.BorderWidthProperty, ValueResetFlags.Local);
        }
    }
     
    private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        if (e.Row.IsExpanded)
        {
            e.CellElement.DrawBorder = false;
        }
        else
        {
            e.CellElement.ResetValue(Telerik.WinControls.UI.LightVisualElement.DrawBorderProperty, ValueResetFlags.Local);
        }
     
        if (e.CellElement.IsCurrent)
        {
            e.CellElement.DrawFill = false;
        }
        else
        {
            e.CellElement.ResetValue(Telerik.WinControls.UI.LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
        }
    }

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. christian
    christian avatar
    4 posts
    Member since:
    Jun 2015

    Posted 12 Nov 2015 in reply to Dess Link to this post

    Thanks Dess.

    Your example works fine.

Back to Top