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

Highlighting rows

2 Answers 361 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brandmuscle
Top achievements
Rank 1
Brandmuscle asked on 26 Aug 2009, 09:00 PM
Is there a way to iterate through the records in a bound grid and highlight (set background color?) for a particular row?

Is there any solution to do this? 

2 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 27 Aug 2009, 12:11 PM
Hello Dan Hickox,

Unfrotunately there is no way to iterate over all grid rows since the rows are virtualized and only a small sub set is available at any time. But there are several other approaches that you can try.

You could easily create a GridViewRow style that manipulates the background under a specific condition:

<Grid> 
    <Grid.Resources> 
        <Style TargetType="telerik:GridViewRow">  
            <Style.Triggers> 
                <DataTrigger Binding="{Binding Path=Size}" Value="100">  
                    <Setter Property="Background" Value="LightGreen"/>  
                </DataTrigger> 
            </Style.Triggers> 
        </Style> 
    </Grid.Resources> 
    <telerik:RadGridView Name="RadGridView1"></telerik:RadGridView> 
</Grid> 
 

This XAML will change the background to LightGreen only when the Size property of a data item is equal to 100.

If you need to make more intricate calculations to determine which row should have its background changed you could use the RowLoaded event which is fire everytime a row comes into view.

void RadGridView1_RowLoaded(object sender, RowLoadedEventArgs e)  
{  
    if (e.Row is GridViewHeaderRow || e.Row is GridViewNewRow)  
        return;  
 
    GridViewRow row = (GridViewRow)e.Row;  
    DataRecord rowRecord = (DataRecord)row.Record;  
    Message dataItem = (Message)rowRecord.Data;  
 
    if (dataItem.Size == 2)  
        row.Background = Brushes.LightBlue;  

Similarly to the XAML code this code-behind will set a blue background to all rows that have size equal to 2.

I have also attached a sample project that you ca use as a reference.

Kind regards,
Milan
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
Brandmuscle
Top achievements
Rank 1
answered on 27 Aug 2009, 02:14 PM
Exactly what I was looking for!

Thanks a buch guys!
Tags
GridView
Asked by
Brandmuscle
Top achievements
Rank 1
Answers by
Milan
Telerik team
Brandmuscle
Top achievements
Rank 1
Share this question
or