Dynamicly update column border.

9 posts, 1 answers
  1. Raymond
    Raymond avatar
    134 posts
    Member since:
    Jul 2010

    Posted 05 Nov 2010 Link to this post

    Hi,

    I've created some style with Visual Style Builder and I'm using it with rad grid view.

    I would like to hide a column border - but just between 2 column headers.

    Particular grid view could have different data sources so I need to set this (hide column splitter) dynamically.

    I've attached the screen shot with marked on the splitter I'd like to hide.

    I browsed through column properties but still couldn't find any matching field to set, please help me with this one...

    Regards.

  2. Raymond
    Raymond avatar
    134 posts
    Member since:
    Jul 2010

    Posted 05 Nov 2010 Link to this post

    Couldn't upload file ...
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 05 Nov 2010 Link to this post

    Hello,

    There is no easy way of doing this, but you could take a look at Jack's example from this post on how to create a custom header.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
  5. Answer
    Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 11 Nov 2010 Link to this post

    Hello Raymond,

    Thank you for your question.

    You can use the ViewCellFormatting event of RadGridView to format the border of the header cells. Please review the following example for hiding the border between two header cells:
    private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridHeaderCellElement headerCell = e.CellElement as GridHeaderCellElement;
        if (headerCell != null)
        {
            if (headerCell.ColumnInfo.Name == "LeftColumnName")
            {
                headerCell.BorderRightColor = Color.Transparent;
                headerCell.BorderRightShadowColor = Color.Transparent;
            }
            else if (headerCell.ColumnInfo.Name == "RightColumnName")
            {
                headerCell.BorderLeftColor = Color.Transparent;
                headerCell.BorderLeftShadowColor = Color.Transparent;
            }
        }
    }

    I hope it helps.

    Best regards,
    Alexander
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  6. Raymond
    Raymond avatar
    134 posts
    Member since:
    Jul 2010

    Posted 16 Nov 2010 Link to this post

    Works for me! Thank You.

  7. Benj
    Benj avatar
    6 posts
    Member since:
    Feb 2012

    Posted 05 Jun 2012 Link to this post

    Hello Alexander,

    I'm currently using Q1 2012. The code you posted doesn't work for me. Maybe because I have applied a theme on my RadGridView or maybe there is a property that I need to set to true. Is there anymore solution to hide the border in between 2 column header cells?
  8. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 07 Jun 2012 Link to this post

    Hello Benjamin,

    Thank you for writing.

    I have modified Alexander's solution a bit. This one should work with all themes:
    private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
      GridHeaderCellElement headerCell = e.CellElement as GridHeaderCellElement;
     
      if (headerCell != null)
      {
        if (headerCell.ColumnInfo.Name == "LeftColumnName")
        {
          headerCell.BorderBoxStyle = BorderBoxStyle.FourBorders;
          headerCell.BorderRightColor = Color.Transparent;
          headerCell.BorderRightShadowColor = Color.Transparent;
          headerCell.ResetValue(LightVisualElement.BorderLeftColorProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.BorderLeftShadowColorProperty, ValueResetFlags.Local);
        }
        else if (headerCell.ColumnInfo.Name == "RightColumnName")
        {
          headerCell.BorderBoxStyle = BorderBoxStyle.FourBorders;
          headerCell.BorderLeftColor = Color.Transparent;
          headerCell.BorderLeftShadowColor = Color.Transparent;
          headerCell.ResetValue(LightVisualElement.BorderRightColorProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.BorderRightShadowColorProperty, ValueResetFlags.Local);
        }
        else
        {
          headerCell.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.BorderLeftColorProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.BorderLeftShadowColorProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.BorderRightColorProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.BorderRightShadowColorProperty, ValueResetFlags.Local);
        }
      }
    }

    I hope this will be useful. Should you have further questions, I would be glad to help.
     
    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 >>
  9. Benj
    Benj avatar
    6 posts
    Member since:
    Feb 2012

    Posted 07 Jun 2012 Link to this post

    Hello Ivan,

    I regret to tell you that your code didn't worked on mine. The result is that nothing happens. I was able to make the border transparent in between the 2 columns on the row section but not on the header section. I'm actually using Office2010Blue theme. I tried experimenting some line of codes:

    headerCell.DrawBorder = true;  //Makes the color of the border black...
    headerCell.BorderColor = Color.White;
    headerCell.BorderColor2 = Color.White;
    headerCell.BorderColor3 = Color.White;
    headerCell.BorderColor4 = Color.White;


    the code above is working but when I use the code below:

    headerCell.DrawBorder = true; //Makes the color of the border black...
    headerCell.BorderRightColor = Color.White;
    headerCell.BorderLeftColor = Color.White;
    headerCell.BorderTopColor = Color.White;
    headerCell.BorderBottomColor = Color.White;


    nothing happens. So maybe there is something wrong with the BorderRightColor , BorderLeftColor ... properties.
  10. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 12 Jun 2012 Link to this post

    Hi Benjamin,

    Thank you for writing back.

    The Office2010Silver theme is a bit more special as the header cells are themed with ImageShape rather than a Gradient + Border. This is why the code fro the previous example does not work. Here is a modified version of the code that works with the Office2010Silver theme:
    private void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
      GridHeaderCellElement headerCell = e.CellElement as GridHeaderCellElement;
     
      if (headerCell != null)
      {
        if (headerCell.ColumnInfo.Name == "LeftColumnName" || headerCell.ColumnInfo.Name == "RightColumnName")
        {
          headerCell.BackgroundShape = null;
     
          headerCell.DrawFill = true;
          headerCell.GradientStyle = GradientStyles.Linear;
          headerCell.BackColor = Color.FromArgb(212, 215, 225);
          headerCell.BackColor2 = Color.FromArgb(221, 224, 230);
          headerCell.NumberOfColors = 2;
     
          headerCell.DrawBorder = true;
          headerCell.BorderBoxStyle = BorderBoxStyle.FourBorders;
          headerCell.BorderTopColor = Color.FromArgb(168, 167, 174);
          headerCell.BorderBottomColor = Color.FromArgb(168, 167, 174);
     
          if (headerCell.ColumnInfo.Name == "LeftColumnName")
          {
            headerCell.BorderRightColor = Color.Transparent;
            headerCell.BorderLeftColor = Color.FromArgb(183, 187, 192);
          }
          else
          {
            headerCell.BorderRightColor = Color.FromArgb(183, 187, 192);
            headerCell.BorderLeftColor = Color.Transparent;
          }
        }
        else
        {
          headerCell.ResetValue(LightVisualElement.BackgroundShapeProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.BackColor2Property, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.NumberOfColorsProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.DrawBorderProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.BorderTopColorProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.BorderBottomColorProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.BorderRightColorProperty, ValueResetFlags.Local);
          headerCell.ResetValue(LightVisualElement.BorderLeftColorProperty, ValueResetFlags.Local);
        }
      }
    }

    I hope this will help. If you need further assistance, do not hesitate to write back.

    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 >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready