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

[Solved] Hiding column programatically

6 Answers 173 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris
Top achievements
Rank 1
Chris asked on 03 May 2009, 04:19 PM
When setting a column to invisible at runtime, when checking the Row.Cells (in the BeginningEdit event), the hidden column is not there. 

Is there a way to check the value that is stored in the hidden cell at that time? 

Currently the grid is bound to the DataTable (using the example by Vladimir Enchev), however I believe this may happen even if the ItemSource is an ObservableCollection.

Thank you in advance

Chris

 

6 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 04 May 2009, 02:15 PM

Hi Chris,

You may get the values of the underlying data from the cells , but also form the underlying data object.

If you have the row , you may check its DataContext. Typically it would be your data with all the fields (including those not visible on screen at the moment).

You can cast the Row.DataContext to your business object and check relevant values.

 Regards,

Pavel Pavlov
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.
0
Chris
Top achievements
Rank 1
answered on 04 May 2009, 02:23 PM
Hi Pavel,

When checking the value of e.Row.DataContext, I get "Could not evaluate expression".

Chris
0
Pavel Pavlov
Telerik team
answered on 05 May 2009, 01:50 PM
Hi Chris,

In the attached sample we have a RadGridView with three columns. The third column titled "Age" is not visible. Within the BeginningEdit handler we display the value of the 'hidden' Age cell in a Texblock under the grid. I hope this covers your scenario.

Best wishes,
Pavel Pavlov
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.
0
Chris
Top achievements
Rank 1
answered on 05 May 2009, 05:55 PM
Hi Pavel,

Thank you for your replies...

It appears that this may be happening only when bound to the DataTable (see example from Vladimir Enchev at http://blogs.telerik.com/vladimirenchev/posts/09-04-23/lightweight_datatable_for_your_silverlight_applications.aspx).

I then get the "Could not evaluate expression" when checking the e.Row.DataContext. 

What does the DataContext rely on?

Thanks in advance.

Regards,

Chris
0
Accepted
Vlad
Telerik team
answered on 07 May 2009, 09:13 AM
Hi Chris,

You can use reflection to get desired value. Here is an example:
void RadGridView1_BeginningEdit(object sender, Telerik.Windows.Controls.GridViewBeginningEditRoutedEventArgs e) 
   int id = (int)e.Row.DataContext.GetType().GetProperty("ID").GetValue(e.Row.DataContext, null); 


All the best,
Vlad
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.
0
Chris
Top achievements
Rank 1
answered on 08 May 2009, 12:23 PM
Thanks once again for all you help Vlad.  That works great.
Tags
GridView
Asked by
Chris
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Chris
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or