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

Remove border around the GridView

8 Answers 1534 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Technik
Top achievements
Rank 1
Technik asked on 04 May 2011, 02:29 PM
Dear Telerik team,

is there a way to remove the border around the grid ?
In our scenario the grid is nested inside a docking control, which comes with its own border.
therefor we have two borders, which together look like a single thick border, breaking overall consistency.
When opening the Visual UI Editor there is no Visual tree to change anything but the root element, so I guess all drawing
is performed manually. Removing borders from the grids TableElement had no effect either. Any advide is greatly appreciated.

Regards

Falk Wegener
orgAnice Software GmbH

8 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 06 May 2011, 07:51 AM
Hello Falk,

To remove the border from the grid, you have to set the DrawBorder property of the GridViewElement & GroupPanelElement to false.

this.radGridView1.GridViewElement.DrawBorder = false;
this.radGridView1.GridViewElement.GroupPanelElement.DrawBorder = false;

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

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Stefan
Telerik team
answered on 06 May 2011, 08:44 AM
Hi Falk Wegener,

Thank you for writing.

Please refer to Emanuel's suggestion regarding removing the border of RadGridView and the group row (if such exists). 

Additionally, I just want to add that if you do not have a group row, the header top borders will become top border of the grid. To remove them, subscribe to the ViewCellFormattingEvent and remove the top borders of the GridHeaderCellElement and GridTableHeaderCellElements:
      public Form1()
       {
           InitializeComponent();
           radGridView2.ViewCellFormatting += new Telerik.WinControls.UI.CellFormattingEventHandler(radGridView2_ViewCellFormatting);
       }
 
void radGridView2_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
       {
           GridHeaderCellElement headerCell = e.CellElement as GridHeaderCellElement;
           if (headerCell != null)
           {
               headerCell.BorderTopWidth = 0;
                
           }
           GridTableHeaderCellElement headerIndentCell = e.CellElement as GridTableHeaderCellElement;
           if (headerIndentCell != null)
           {
               headerIndentCell.BorderTopWidth = 0;
           }
       }

I hope the provided information addresses your question. Should you have any other questions, do not hesitate to contact us.

Kind regards,
Stefan
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
Technik
Top achievements
Rank 1
answered on 06 May 2011, 12:13 PM
Works perfectly, thank you both.

Falk Wegener
0
Silvia
Top achievements
Rank 1
answered on 07 Oct 2011, 04:37 PM
Hi, I need to remove the border between rows i try with 
this.radGridView1.GridViewElement.DrawBorder = false;
this.radGridView1.GridViewElement.GroupPanelElement.DrawBorder = false;

but GridViewElement is not accepted for the grid
 
0
Stefan
Telerik team
answered on 11 Oct 2011, 03:12 PM
Hi Silvia,

Thank you for writing.

You can remove the borders between the rows in RadGridView by setting the cells top and bottom border widths to 0. To introduce such a setting, you should make use of the ViewCellFormatting event of RadGridView. The following code snippet, demonstrates how to achieve such a look and also it keeps the top borders of RadGridView:
void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    //keep the top borders of the grid
    if (e.CellElement is GridHeaderCellElement || e.CellElement is GridTableHeaderCellElement || e.CellElement is GridHeaderIndentCellElement)
    {
        e.CellElement.BorderTopWidth = 1;
    }
    //remove all cells top and bottom borders
    else
    {
        e.CellElement.BorderTopWidth = 0;
        e.CellElement.BorderBottomWidth = 0;
    }
}

I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us. 

All the best,
Stefan
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Andrey Smiryagin
Top achievements
Rank 1
answered on 18 Mar 2015, 11:46 PM
How would I achieve the same on a child template grid?
0
Andrey Smiryagin
Top achievements
Rank 1
answered on 18 Mar 2015, 11:47 PM
To clarify, how would I remove the border around the grid of a child template in a hierarchical grid?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Mar 2015, 11:58 AM
Hello Andrey,

Thank you for writing.

If I understand your requirement correctly you are trying to remove the thick border around the child template. Please refer to the attached ChildTemplateBorder.png. For this purpose, you can use the ViewCellFormatting event and manipulate the GridDetailViewCellElement.Padding property:
private void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    GridDetailViewCellElement childCell = e.CellElement as GridDetailViewCellElement;
    if (childCell != null)
    {
        childCell.BorderBoxStyle = BorderBoxStyle.SingleBorder;
        childCell.BorderWidth = 0;
        childCell.Padding = new Padding(0);
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.BorderWidthProperty, ValueResetFlags.Local);
        e.CellElement.ResetValue(LightVisualElement.PaddingProperty, ValueResetFlags.Local);
    }
}

The result is illustrated on the attached NoChildTemplateBorder.png. If this is not the expected result, please specify in details the requirement that you are trying to achieve.

I hope this information helps. Should you have further questions, I would be glad to help.
 
Regards,
Dess
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GridView
Asked by
Technik
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Stefan
Telerik team
Technik
Top achievements
Rank 1
Silvia
Top achievements
Rank 1
Andrey Smiryagin
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or