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

save gridview checkbox header

2 Answers 67 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Gili
Top achievements
Rank 1
Gili asked on 17 Apr 2013, 08:28 AM
when trying to save radgridview setting with  
http://demos.telerik.com/silverlight/#PersistenceFramework/GridViewCustomSerialization
  i have a problem because one of the gridview column header is a checkbox 
<telerik:GridViewCheckBoxColumn  IsReadOnly="False" DataMemberBinding="{Binding checkboxcp, Mode=TwoWay}" AutoSelectOnEdit="True"  UniqueName="CheckBox_mo"    >
    <telerik:GridViewCheckBoxColumn.Header>
        <CheckBox  Name="chStandard" Checked="CheckBox_Checked" Content="is valid"  IsChecked="False" Unchecked="chStandard_Unchecked"  />
    </telerik:GridViewCheckBoxColumn.Header>
    <telerik:GridViewCheckBoxColumn.CellStyleSelector>
and it saves the header as string and loads it as string .and not as real checkbox

2 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 22 Apr 2013, 12:02 PM
Hi Gili,

When using the PersistenceFramework to persist complex controls such as the RadGridView, you need to manually configure the properties that will be persisted as well as the methods that persist them. In our online examples, we provide a sample demonstrating how to persist a sample RadGridView control here the column headers are strings. And if you need to further customize the GridView, its settings or what has to be persisted, you need to modify the custom RadGridView PropertyProvider. In your case the changes you need to implement in the online sample are :
  • change the type of the Header property in the ColumnProxy class to be object
  • add a Boolean property in the ColumnProxy class to indicate if a column is a GridViewCheckBoxColumn
public class ColumnProxy
{
    public string UniqueName { get; set; }
    public int DisplayOrder { get; set; }
    public object Header { get; set; }
    public GridViewLength Width { get; set; }
    public bool IsVisible { get; set; }
    public bool IsCheckBoxColumn { get; set; }
}
  • Change the GridViewCustomPropertyProvider ProvideValue method in the case where the persisted property name is Columns to save the header as an object and to set the IsCheckBoxColumn property based on the type of the persisted column
public object ProvideValue(CustomPropertyInfo customPropertyInfo, object context)
{
    RadGridView gridView = context as RadGridView;
    if (customPropertyInfo.Name == "Columns")
    {
        // create proxies for all of the columns and save only specific properties
        List<ColumnProxy> proxies = new List<ColumnProxy>();
        foreach (GridViewColumn column in gridView.Columns)
        {
            proxies.Add(new ColumnProxy()
            {
                UniqueName = column.UniqueName,
                Header = column.Header,
                DisplayOrder = column.DisplayIndex,
                Width = column.Width,
                IsCheckBoxColumn = column is GridViewCheckBoxColumn
            });
        }
        return proxies;
    }
    ...
}
  • Change the GridViewCustomPropertyProvider RestoreValue method by adding a separate logic for restoring columns of type GridViewSelectColumn
public void RestoreValue(CustomPropertyInfo customPropertyInfo, object context, object value)
{
    RadGridView gridView = context as RadGridView;
 
    switch (customPropertyInfo.Name)
    {
        case "Columns":
            {
                List<ColumnProxy> columnProxies = value as List<ColumnProxy>;
 
                foreach (ColumnProxy proxy in columnProxies)
                {
                    if (proxy.IsCheckBoxColumn)
                    {
                        GridViewCheckBoxColumn checkBoxColumn = gridView.Columns[proxy.UniqueName] as GridViewCheckBoxColumn;
                        if (checkBoxColumn != null)
                        {
                            checkBoxColumn.DisplayIndex = proxy.DisplayOrder;
                            (checkBoxColumn.Header as System.Windows.Controls.CheckBox).IsChecked = (proxy.Header as System.Windows.Controls.CheckBox).IsChecked;
                            checkBoxColumn.Width = proxy.Width;
                            checkBoxColumn.IsVisible = proxy.IsVisible;
                        }
                    }
                    else
                    {
                        GridViewColumn column = gridView.Columns[proxy.UniqueName];
                        if (column != null)
                        {
                            column.DisplayIndex = proxy.DisplayOrder;
                            column.Header = proxy.Header;
                            column.Width = proxy.Width;
                            column.IsVisible = proxy.IsVisible;
                        }
                    }
                }
            }
            break;
        ...
    }
}

I attached a sample solution demonstrating this approach so please give it a try and let me know if it helps.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Gili
Top achievements
Rank 1
answered on 22 Apr 2013, 12:13 PM
thank you very much
Tags
PersistenceFramework
Asked by
Gili
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Gili
Top achievements
Rank 1
Share this question
or