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

[Solved] Suppress binding to business object properties when column is not visible

3 Answers 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James Pearson
Top achievements
Rank 1
James Pearson asked on 29 Jan 2010, 10:36 PM
Binding an IEnumerable collection of business objects to grid using the simple binding method.  Users can choose to hide columns on an options page.  This causes page to enumerate the columns in the grid and set Visible=False.  However, I've noticed that the grid still attempts to bind to the column even though the column is not visible.  I'm using custom sorting and no filtering or grouping.  I've tried setting the DataField property to an empty string or Nothing, but grid still attempts to bind the column.  Of course, without a value for DataField, it throws an exception.

Is there a way to suppress binding to non-visible columns?

3 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 01 Feb 2010, 11:49 AM
Hello James,

I suggest you set the RetrieveAllDataFields property of the grid to false (the default value is true) to see whether this produces the desired result. Note that you can use the AdditionalDataFieldNames array to add fields that has to be taken into account for sorting, grouping, etc. operations. See this topic from the documentation for further details.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
James Pearson
Top achievements
Rank 1
answered on 01 Feb 2010, 01:40 PM
Unfortunately, RetrieveAllDataFields set to false does not have the effect that columns with visible=false are not retrieved and bound.  I can verify this by setting a breakpoint inside the getter and see that the grid retrieves the value of a property even when the grid column it's bound to is not visible.
0
Sebastian
Telerik team
answered on 01 Feb 2010, 02:02 PM
Hello James,

Please excuse me for not being descriptive enough in my previous reply - actually with the proposed setting you will need to remove the hidden columns in order to prevent the property values being fetched. If you would like to operate with the properties of your business objects which are not part of the binding logic, you will need to reference them strictly through the AdditionalDataFieldNames array.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
James Pearson
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
James Pearson
Top achievements
Rank 1
Share this question
or