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

How to hide columns after binding data

3 Answers 401 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pavel
Top achievements
Rank 1
Pavel asked on 07 Jul 2009, 11:33 AM
Hi,

I have a gridview with datasource defined and I just want only some of the columns to be visible. But when I bind data using DataSource property, my design time column visibility settings are lost and all columns are shown.

I'm using Q2 2009 trial version, but in Q1 everything works fine...

Thanks for solution.

PK

3 Answers, 1 is accepted

Sort by
0
Accepted
Joel Kraft
Top achievements
Rank 2
answered on 07 Jul 2009, 01:03 PM
I filed the same issue (in the Q1 service pack) as a bug report, you have to set the AutoGenerateColumns on the GridViewTemplate to false. Below is a chunk from my extender class that adds a SuppressAutoGenerateColumns function to both the RadGridView and GridViewTemplate and recurses through any child GridViewTemplates. Call it once on the grid and it will behave as before.

    public static class RadGridViewExtender 
    { 
        public static void SuppressAutoGenerateColumns(this RadGridView gridView) 
        { 
            SuppressAutoGenerateColumns(gridView.MasterGridViewTemplate); 
        } 
 
        public static void SuppressAutoGenerateColumns(this GridViewTemplate gridViewTemplate) 
        { 
            gridViewTemplate.AutoGenerateColumns = false
            foreach (GridViewTemplate t in gridViewTemplate.ChildGridViewTemplates) 
            { 
                SuppressAutoGenerateColumns(t); 
            } 
        } 
    } 

0
Pavel
Top achievements
Rank 1
answered on 07 Jul 2009, 01:24 PM
Problem solved... Thanks!
0
Accepted
Julian Benkov
Telerik team
answered on 09 Jul 2009, 08:58 AM
Hello Pavel,

In the previous version of RadGridView we used to make checks whether the new DataSource object properties are the same like the previous data source properties and in this situation we only loaded the new data. This approach created some inconsistent states in RadGridView, problems with rebuilding the internal data, and performance issues as well.

In the new version when a new DataSource is used, RadGridView makes clean rebind operation. In your scenario where the DataSource is frequently changed, you can set AutoGenerateColumns property of MasterGridViewTemplate to false and all your columns settings will be kept correctly.

public GridForm() 
    InitializeComponent(); 
 
    this.radGridView1.MasterGridViewTemplate.AutoGenerateColumns = false

Thank you for your answer Joel.

Best wishes,
Julian Benkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Pavel
Top achievements
Rank 1
Answers by
Joel Kraft
Top achievements
Rank 2
Pavel
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or