# Creating custom rows

**RadGridView** provides a variety of visual cells per row with different functionality and purpose. However, in some cases you may need to display custom elements, not a single cell per column. This article demonstrates a sample approach how to create a custom row element.

## Custom new row

Consider the **RadGridView** is populated with data form Northwind.Products table.

```C#
public static object DataSource;

private void CreateCustomNewRow_Load(object sender, EventArgs e)
{
    this.productsTableAdapter.Fill(this.nwindDataSet.Products);

    DataSource = this.nwindDataSet.Products.Take(20);
 
    this.radGridView1.TableElement.ViewInfo.TableAddNewRow.Height = 250;
    this.radGridView1.DataSource = this.nwindDataSet.Products;
    this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
}
```

```VB.NET
Public Shared DataSource As Object
Private Sub CreateCustomNewRow_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Me.ProductsTableAdapter.Fill(Me.NwindDataSet.Products)

    DataSource = Me.NwindDataSet.Products.Take(20)

    Me.RadGridView1.TableElement.ViewInfo.TableAddNewRow.Height = 250
    Me.RadGridView1.DataSource = Me.NwindDataSet.Products
    Me.RadGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill
End Sub
```

> note In order to enlarge the new row's height, you can set the TableElement.ViewInfo.TableAddNewRow. **Height** property.

On the new row we will display a **RadChartViewElement** visualizing the Products data. For this purpose we should follow the steps below:

> note You can replace the **RadChartViewElement** with any **RadElement** or a set of elements.

> caption Figure 1: The new row is replaced with the custom one

![WinForms RadGridView The new row is replaced with the custom one](https://www.telerik.com/products/winforms/documentation/assets/614ad58b78f34eb6a34134fca8c38e46/gridview-rows-custom-rows001.png)

1\. Create a descendant of the **GridRowElement** and override its **CreateChildElements** where you should add a single **GridCellElement** that contains the chart. The **IsCompatible** method  determines for which **GridViewRowInfo** the custom row element is applicable:

```C#

public class CustomGridRowElement : GridRowElement
{
    private GridCellElement cellElement;
    private RadChartElement radChartElement;
    
    public CustomGridRowElement()
    {
    }
        
    protected override void CreateChildElements()
    {
        base.CreateChildElements();
        this.cellElement = new GridCellElement(null, this);
        this.cellElement.StretchHorizontally = true;
        this.cellElement.StretchVertically = true;
        this.Children.Add(cellElement);
        
        this.radChartElement = new RadChartElement();
        
        LineSeries series = new LineSeries();
        
        this.radChartElement.View.ShowSmartLabels = true;
        this.radChartElement.ShowLegend = true;
        this.radChartElement.View.Series.Add(series);

        this.cellElement.Children.Add(this.radChartElement);
        this.cellElement.ClipDrawing = true;
        
        series.CategoryMember = "CategoryID";
        series.ValueMember = "UnitPrice";
        series.DataSource = DataSource;
    }
        
    public override bool IsCompatible(GridViewRowInfo data, object context)
    {
        return data is CustomGridViewRowInfo;
    }
}

```

```VB.NET

Public Class CustomGridRowElement
    Inherits GridRowElement
    Private cellElement As GridCellElement
    Private radChartElement As RadChartElement

    Public Sub New()
    End Sub

    Protected Overrides Sub CreateChildElements()
        MyBase.CreateChildElements()
        Me.cellElement = New GridCellElement(Nothing, Me)
        Me.cellElement.StretchHorizontally = True
        Me.cellElement.StretchVertically = True
        Me.Children.Add(cellElement)

        Me.radChartElement = New RadChartElement()

        Dim series As New LineSeries()

        Me.radChartElement.View.ShowSmartLabels = True
        Me.radChartElement.ShowLegend = True
        Me.radChartElement.View.Series.Add(series)

        Me.cellElement.Children.Add(Me.radChartElement)
        Me.cellElement.ClipDrawing = True

        series.CategoryMember = "CategoryID"
        series.ValueMember = "UnitPrice"
        series.DataSource = DataSource
    End Sub

    Public Overrides Function IsCompatible(data As GridViewRowInfo, context As Object) As Boolean
        Return TypeOf data Is CustomGridViewRowInfo
    End Function
End Class

```

2\. Create a descendant of the **GridViewNewRowInfo** and specify that it uses the row element from the previous step by overriding its **RowElementType** property.

```C#
    
public class CustomGridViewRowInfo : GridViewNewRowInfo
{
    public CustomGridViewRowInfo(GridViewInfo viewInfo) : base(viewInfo)
    {
    }
        
    public override Type RowElementType
    {
        get
        {
            return typeof(CustomGridRowElement);
        }
    }
}

```

```VB.NET

Public Class CustomGridViewRowInfo
    Inherits GridViewNewRowInfo
    Public Sub New(viewInfo As GridViewInfo)
        MyBase.New(viewInfo)
    End Sub

    Public Overrides ReadOnly Property RowElementType() As Type
        Get
            Return GetType(CustomGridRowElement)
        End Get
    End Property
End Class

```

3\. The last step is to subscribe to the **CreateRowInfo** event and replace the default **GridViewNewRowInfo** with your custom one.

> important You should subscribe to the **CreateRowInfo** event at design time in order to ensure that the event will be fired when a data row have to be created.

```C#
        
private void radGridView1_CreateRowInfo(object sender, GridViewCreateRowInfoEventArgs e)
{
    if (e.RowInfo is GridViewNewRowInfo)
    {
        e.RowInfo = new CustomGridViewRowInfo(e.ViewInfo);
    }
}

```

```VB.NET

Private Sub radGridView1_CreateRowInfo(sender As Object, e As GridViewCreateRowInfoEventArgs) Handles RadGridView1.CreateRowInfo
    If TypeOf e.RowInfo Is GridViewNewRowInfo Then
        e.RowInfo = New CustomGridViewRowInfo(e.ViewInfo)
    End If
End Sub

```

## See Also

* [Adding and Inserting Rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/adding-and-inserting-rows)

* [Conditional Formatting Rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/conditional-formatting-rows)

* [Drag and Drop](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/drag-and-drop)

* [Formatting Rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/formatting-rows)

* [GridViewRowInfo](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/gridviewrowinfo)

* [Iterating Rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/iterating-rows)

* [New Row](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/new-row)

* [Painting Rows](https://www.telerik.com/products/winforms/documentation/controls/gridview/visual-elements/rows/painting-rows)

* [How to Create a Custom Data Row Element in RadGridView](https://www.telerik.com/products/winforms/documentation/knowledge-base/custom-grid-data-row-element)
