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

Dynamicly update column border.

8 Answers 167 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 05 Nov 2010, 02:04 PM

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.

8 Answers, 1 is accepted

Sort by
0
Raymond
Top achievements
Rank 1
answered on 05 Nov 2010, 02:14 PM
Couldn't upload file ...
0
Emanuel Varga
Top achievements
Rank 1
answered on 05 Nov 2010, 02:45 PM
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
0
Accepted
Alexander
Telerik team
answered on 11 Nov 2010, 10:02 AM
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
0
Raymond
Top achievements
Rank 1
answered on 16 Nov 2010, 12:08 PM

Works for me! Thank You.

0
Benj
Top achievements
Rank 2
answered on 06 Jun 2012, 03:41 AM
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?
0
Ivan Petrov
Telerik team
answered on 07 Jun 2012, 03:00 PM
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 >>
0
Benj
Top achievements
Rank 2
answered on 08 Jun 2012, 04:16 AM
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.
0
Ivan Petrov
Telerik team
answered on 12 Jun 2012, 09:14 AM
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 >>
Tags
GridView
Asked by
Raymond
Top achievements
Rank 1
Answers by
Raymond
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Alexander
Telerik team
Benj
Top achievements
Rank 2
Ivan Petrov
Telerik team
Share this question
or