New to Telerik UI for WinFormsStart a free 30-day trial

Emulate Cell Merge in RadGridView

Updated on Nov 3, 2025
Product VersionProduct
2018.3.1016RadGridView for WinForms

Description

It is a common case to merge the cells that have same contents. Currently this is not supported out of the box in rad grid view. This article demonstrates how you can emulate this mode by hiding the borders and the text of the cell where the contents are exactly the same.

Solution

In order to determine which sells have equal values you need a method that checks the contents of the previous and next cells. This way you will determine where the border should be hidden. The method will be called from the CellFormatting event handler. Here is a sample implementation for this.

C#
private void RadGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    e.CellElement.ResetValue(LightVisualElement.DrawBorderProperty, Telerik.WinControls.ValueResetFlags.Local);
    e.CellElement.ResetValue(LightVisualElement.DrawTextProperty, Telerik.WinControls.ValueResetFlags.Local);

    if (e.Column.Name == "CategoryID")
    {              
        HideBorders(e, radGridView1);
    }
}
private void HideBorders(CellFormattingEventArgs e, RadGridView grid)
{
    string themeName = grid.ElementTree.ThemeName;

    if (themeName == "Desert")
    {
        return;
    }

    bool isSpecialTheme = (themeName == "VisualStudio2012Dark") ||
                        (themeName == "VisualStudio2012Light") ||
                        (themeName == "Windows8");

    int index = e.Row.ViewInfo.ChildRows.IndexOf(e.Row);

    if (index < 0)
    {
        return;
    }

    bool shouldDrawText = true;

    if (index -1 >= 0)
    {
        shouldDrawText = (grid.ChildRows[index].Cells[e.ColumnIndex].Value + "") != (grid.ChildRows[index - 1].Cells[e.ColumnIndex].Value + "");
        e.CellElement.DrawText = shouldDrawText;
        e.CellElement.DrawBorder = shouldDrawText;
    }
  

    if (index + 1 < grid.ChildRows.Count)
    {
        bool shouldRemoveBorder = (grid.ChildRows[index].Cells[e.ColumnIndex].Value + "") == (grid.ChildRows[index + 1].Cells[e.ColumnIndex].Value + "");
        if (!isSpecialTheme)
        {
            e.CellElement.DrawBorder = !shouldRemoveBorder && shouldDrawText;
        }
        

        e.CellElement.RowElement.DrawBorder = !shouldRemoveBorder;
    }
}

The following image shows the result from the above code.

emulate-cell-merge

The following article shows more complex ways for this: RadGridView Merge Cells

In this article
DescriptionSolution
Not finding the help you need?
Contact Support