save gridview checkbox header

3 posts, 0 answers
  1. Gili
    Gili avatar
    14 posts
    Member since:
    Jan 2013

    Posted 17 Apr 2013 Link to this post

    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. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 22 Apr 2013 Link to this post

    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.

  3. DevCraft banner
  4. Gili
    Gili avatar
    14 posts
    Member since:
    Jan 2013

    Posted 22 Apr 2013 Link to this post

    thank you very much
Back to Top