Hello,
I'd like to remove the horizontal border in a grid within groups (GridViewColumnGroup not GroupDescriptor).
See the attached image, the green (verticals) borders are ok the red (horizontal) borders between the cells in the group are the ones I'd like to remove. (For normal cells and cells of the summary row)
I've tried the normal formatting events, but I found no information if a cell/row is inside a group?
So is this possible at all?
--
Also the GridViewColumnGroupRow.ColumnCollection is marked deprecated, so what is the best way to do this (the ColumnNameCollection dosen't help)?
GridViewColumnGroupRow groupRow =
new
GridViewColumnGroupRow();
groupRow.Columns.Add(
this
.kMRadGridView1.Columns[
"column"
]);
Kind regars
7 Answers, 1 is accepted
Thank you for writing.
In this case, there is no need to check if the cell is inside a group, you can only check the cell element type. For example:
private
void
RadGridView1_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement
is
GridDataCellElement || e.CellElement
is
GridSummaryCellElement)
{
e.CellElement.BorderBoxStyle = BorderBoxStyle.FourBorders;
e.CellElement.BorderBottomWidth = 0;
e.CellElement.BorderTopWidth = 0;
}
else
{
e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderBottomWidthProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderTopWidthProperty, ValueResetFlags.Local);
}
}
Let me know if you have additional questions.
Regards,
Dimitar
Telerik
Hello Dimitar,
this is going in the right direction, but now there aren't any horizontal lines.
I'd like to keep the lines after the header / before the summary row and between the records (green in the screenshot)
Regards,
Christian
Thank you for writing back.
You should remove the top/bottom border of the first cells only. For example:
private
void
RadGridView1_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(e.CellElement
is
GridSummaryCellElement || e.CellElement
is
GridDataCellElement )
{
if
(e.Column.Name ==
"CustomerID"
)
{
e.CellElement.BorderBoxStyle = BorderBoxStyle.FourBorders;
e.CellElement.BorderBottomWidth = 0;
}
else
if
(e.Column.Name ==
"Phone"
)
{
e.CellElement.BorderBoxStyle = BorderBoxStyle.FourBorders;
e.CellElement.BorderTopWidth = 0;
}
else
{
e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderBottomWidthProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderTopWidthProperty, ValueResetFlags.Local);
}
}
else
{
e.CellElement.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderBottomWidthProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BorderTopWidthProperty, ValueResetFlags.Local);
}
}
Please let me know if there is something else I can help you with.
Dimitar
Telerik
Hello Dimitar,
this could work, but I need a generic solution, because I have a derived grid. And I'd like to implement this as a custom property to switch it on/off.
Regards,
Christian
Thank you for writing back.
In this case, you can show the entire row border and hide the cells top and bottom borders:
private
void
RadGridView1_ViewRowFormatting(
object
sender, RowFormattingEventArgs e)
{
var row = e.RowElement;
row.DrawBorder =
true
;
row.BorderBoxStyle = BorderBoxStyle.FourBorders;
row.BorderTopColor = Color.Red;
row.BorderTopWidth = 2;
}
private
void
RadGridView1_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
e.CellElement.BorderBoxStyle = BorderBoxStyle.FourBorders;
e.CellElement.BorderTopWidth = 0;
e.CellElement.BorderBottomWidth = 0;
}
I hope this will be useful.
Dimitar
Telerik
Hello Dimitar,
this kinda works, but the grid becomes slow so I've decided not to pursue this any further. Also the are drawing issues with the Hottrack / Selection (see blue vertical lines in screenshot)
Regards,
Christian
Thank you for writing back.
Generally setting the styles should not have any performance impact. If you want we can investigate this, however we will neen more information and it woud be better to open a support ticked for this.
In addition you can change the border of the selcted cell with the following code:
private
void
RadGridView1_ViewCellFormatting(
object
sender, CellFormattingEventArgs e)
{
if
(!e.CellElement.IsCurrent)
{
e.CellElement.BorderBoxStyle = BorderBoxStyle.FourBorders;
e.CellElement.BorderTopWidth = 0;
e.CellElement.BorderBottomWidth = 0;
}
else
{
e.CellElement.BorderTopWidth = 1;
e.CellElement.BorderBottomWidth = 1;
e.CellElement.BorderBoxStyle = BorderBoxStyle.FourBorders;
e.CellElement.BorderTopColor = Color.Red;
e.CellElement.BorderBottomColor = Color.Red;
}
}
I hope this will be useful.
Regards,
Dimitar
Telerik