WPF RadGridView Style a cell depending on another cell in the same row dynamically.

1 Answer 232 Views
GridView Styling
Dean
Top achievements
Rank 1
Dean asked on 31 May 2021, 08:41 AM

The item source of this gridview is bound to a DataTable programmatically. The amount of columns change depending on how many days the user wants to see. I need all of the Date cells to have a foreground (Text colour) of red if they do not equal the number in the expected column.

I have tried many ways of accomplishing this but nothing seems to work.

Thank you in advance.

Dean
Top achievements
Rank 1
commented on 31 May 2021, 08:42 AM

<telerik:RadGridView telerik:StyleManager.Theme="Fluent"
x:Name="daGrid" Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2"
AutoGenerateColumns="True" Margin="15,5,5,5" CanUserDeleteRows="False"
CanUserInsertRows="False" ShowGroupPanel="False" Grid.RowSpan="11"
CanUserFreezeColumns="False" CanUserGroupColumns="False"
ItemsSource="{Binding IsAsync=True}" SelectionChanged="daGrid_SelectionChanged"
AutoGeneratingColumn="daGrid_AutoGeneratingColumn" CellValidating="daGrid_CellValidating">
<telerik:RadContextMenu.ContextMenu>
<telerik:RadContextMenu x:Name="GridContextMenu" Opened="GridContextMenu_Opened"
ItemContainerStyle="{StaticResource MenuItemContainerStyle1}"
telerik:StyleManager.Theme="Windows8" ItemClick="GridContextMenu_ItemClick"
/>
</telerik:RadContextMenu.ContextMenu>
</telerik:RadGridView>

This is the xaml code for the gridview.

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 01 Jun 2021, 10:09 AM

Hello Dean,

Thank you for the provided image and code snippet.

Based on them I prepared a small sample project which I believe achieves your requirement. For the purpose, I've used the CellStyleSelector property of the columns and in the SelectStyle method, I compare the value of the current cell with the one from the Expected column.

Please have a look at the attached project and let me know if it provides the desired result.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
GridView Styling
Asked by
Dean
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or