How to Save/Load Layout with Custom Columns in RadGridView
Environment
Product Version | Product | Author |
---|---|---|
2021.3.914 | RadGridView for WinForms | Desislava Yordanova |
Description
RadGridView provides a convenient API for creating custom columns with custom cell elements. However, the XML layout appears to be removing all the columns and related grid data after adding the custom column.
A common requirement is to save the layout with all the columns in the grid and restore this layout at a later moment together with the custom columns.
Solution
For the serialization, the custom column needs to have a parameterless constructor in order to be able to load the layout later:
public class ProgressBarColumn : GridViewDataColumn
{
public ProgressBarColumn()
{
}
public ProgressBarColumn(string fieldName) : base(fieldName)
{
}
public override Type GetCellType(GridViewRowInfo row)
{
if (row is GridViewDataRowInfo)
{
return typeof(ProgressBarCellElement);
}
return base.GetCellType(row);
}
}
Public Class ProgressBarColumn
Inherits GridViewDataColumn
Public Sub New()
End Sub
Public Sub New(ByVal fieldName As String)
MyBase.New(fieldName)
End Sub
Public Overrides Function GetCellType(ByVal row As GridViewRowInfo) As Type
If TypeOf row Is GridViewDataRowInfo Then
Return GetType(ProgressBarCellElement)
End If
Return MyBase.GetCellType(row)
End Function
End Class