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

Hide Cell Content Based on Condition

4 Answers 187 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 02 Feb 2014, 10:16 PM
For certain rows I don't want the cell to be editable or show any content. Maybe focusable but user wouldn't be able to go into edit mode. This behavior would be based on a value of the row's data context. Essentially, certain attributes don't apply to certain rows, so user shouldn't be able to interact with those columns at all.

How can you go about doing this that doesn't require that I recreate the data template?

4 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 03 Feb 2014, 01:28 PM
Hello Carlos,

If you want to style conditionally RadGridView cells, then you can use GridView's CellStyleSelector. Please check this help article for a reference. You can check this online demo as well (the same example is available in your local copy of WPF demos). It would be something like:
<my:StadiumCapacityStyle x:Key="stadiumCapacityStyle">
       <my:StadiumCapacityStyle.BigStadiumStyle>
           <Style TargetType="telerik:GridViewCell">
               <Setter Property="IsEnabled" Value="True"/>
           </Style>
       </my:StadiumCapacityStyle.BigStadiumStyle>
       <my:StadiumCapacityStyle.SmallStadiumStyle>
           <Style TargetType="telerik:GridViewCell">
               <Setter Property="IsEnabled" Value="False" />
           </Style>
       </my:StadiumCapacityStyle.SmallStadiumStyle>
   </my:StadiumCapacityStyle>




Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Carlos
Top achievements
Rank 1
answered on 03 Feb 2014, 08:42 PM
Thanks for the reply; however, I'm actually trying to hide the contents of the cell not just disable them. For example, there's a property that doesn't apply to one of the rows, so we don't even want to show the checkbox in the cell. Binding the visibility of the cell hid the border of the cell which isn't what we want either.

There doesn't seem to be an ItemDataBound event for WPF so we tried CellLoaded to change the visibility of the content in code but CellLoaded didn't seem to be synonymous to ItemDataBound as it didn't fire consistently, for example when we clear the list and repopulated.

What else would you recommend?
0
Accepted
Yoan
Telerik team
answered on 07 Feb 2014, 06:48 AM
Hi Carlos,

In this case, you can use CellTemplateSelector and return an empty TextBlock for the cell you want. However, if you want to disable the edit mode of the cell, you will need a CellStyleSelector, too. Then you can set cell's IsEnabled property to false. I have prepared a sample project, which demonstrates the approach.

Please give it a try and let me know how it works for you.



Regards,
Yoan
Telerik

Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

0
Carlos
Top achievements
Rank 1
answered on 08 Feb 2014, 05:56 AM
That worked like a charm. Just what I was after, no need to redefine the whole cell template. Thanks for taking the time to look into it.
Tags
GridView
Asked by
Carlos
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Carlos
Top achievements
Rank 1
Share this question
or