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

RadGridView row color change on GridViewCheckBoxColumn data.

2 Answers 71 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hareesh
Top achievements
Rank 1
Hareesh asked on 11 Nov 2011, 12:21 PM
Hi,
I am using RadGridView to display data. This grid has a GridViewCheckBoxColumn and it is binded to data from DB. My requirement is to show different background color for the row for which the check box is checked while binding the grid. Also it should toggle the row background color for the Check/Uncheck. I have google for this & found some codes(http://www.telerik.com/help/winforms/gridview-rows-formatting-rows.html), but I can't find a RowFormatting event and Telerik.WinControls.UI.RowFormattingEventArgs. Do we need to add any reference for this? My grid is as follows:

<telerik:RadGridView x:Name="GrdCoveredEntityTable" IsFilteringAllowed="False"
                             AutoGenerateColumns="False" 
                             MinHeight="200" MaxHeight="200" Width="Auto"
                             FrozenColumnCount="{Binding Value, ElementName=RadSlider1, Mode=TwoWay,NotifyOnValidationError=True}"  BorderThickness="2" HorizontalAlignment="Stretch"
                             CanUserReorderColumns="False" ShowGroupPanel="False" CanUserResizeColumns="True" CanUserDeleteRows="False"
                             CanUserSelect="False">
                            <telerik:RadGridView.Columns>
                                <telerik:GridViewCheckBoxColumn UniqueName="Select" Width="60" Header="Select" DataMemberBinding="{Binding Selection}" ></telerik:GridViewCheckBoxColumn>
                                <telerik:GridViewComboBoxColumn UniqueName="TypeId"  Width="150" DataMemberBinding="{Binding TypeId}"
                                                SelectedValueMemberPath="ID"
                                                DisplayMemberPath="textValue" Header="Covered Entity Type"/>
                                <telerik:GridViewDataColumn UniqueName="id" DataMemberBinding="{Binding ID}" Header="Value" IsGroupable="False" IsVisible="False" />
                                <telerik:GridViewDataColumn UniqueName="name" DataMemberBinding="{Binding Name}" Header="Name" IsGroupable="False" Width="250" />
                                <telerik:GridViewDataColumn UniqueName="address" DataMemberBinding="{Binding Address}" Header="Address" IsGroupable="False" Width="250" />
                                <telerik:GridViewDataColumn UniqueName="city" DataMemberBinding="{Binding City}" Header="City" IsGroupable="False" Width="200" />
                                <telerik:GridViewDataColumn UniqueName="state" DataMemberBinding="{Binding State}" Header="State" IsGroupable="False" Width="200" />
                                <telerik:GridViewDataColumn UniqueName="zip" DataMemberBinding="{Binding Zip}" Header="Zip" IsGroupable="False" Width="100" />
                                <telerik:GridViewDataColumn UniqueName="contactName" DataMemberBinding="{Binding ContactName}" Header="Contact Name" IsGroupable="False" Width="250" />
                                <telerik:GridViewDataColumn UniqueName="contactPhone" DataMemberBinding="{Binding ContactPhone}" Header="Contact Phone" IsGroupable="False" Width="150" />
                                <telerik:GridViewDataColumn UniqueName="contactEmail" DataMemberBinding="{Binding ContactEmail}" Header="Contact Email" IsGroupable="False" Width="200" />
                            </telerik:RadGridView.Columns>
                        </telerik:RadGridView>




2 Answers, 1 is accepted

Sort by
0
Hareesh
Top achievements
Rank 1
answered on 14 Nov 2011, 08:35 AM
No reply?? Please help me..
0
J
Top achievements
Rank 1
answered on 17 Nov 2011, 09:33 PM
Hey Hareesh,

You need to set the binding in the code behind as hinted in the link you provided. To set the bindings, I do the following:

    historicalLandStatus.LoadingRow += historicalLandStatus_LoadingRow;
}
 
private void historicalLandStatus_LoadingRow(object sender, DataGridRowEventArgs e) {
    var color = new Binding("BackColor");
    e.Row.SetBinding(GridViewRow.BackgroundProperty, color);
}

where historicaLandStatus is a GridView. I use LoadingRow as this sets the bindings the moment the row is loaded. I currently am looking to find a way for the background color to update when the binding source updates (the reason I am viewing your thread) and cannot advise on how to do this. Hopefully someone else will chime in.

EDIT:
Just to further clarify, in my example you need a property of type SolidColorBrush on your view model that exposes the desired back color. If you want to use your same bindings, something like

public SolidColorBrush BackColor {
get {
 return Selection ? new SolidColorBrush(Colors.Blue) : new SolidColorBrush(Colors.Transparent);
}
}

or you can use a binding converter and bind directly to Selection.
Tags
GridView
Asked by
Hareesh
Top achievements
Rank 1
Answers by
Hareesh
Top achievements
Rank 1
J
Top achievements
Rank 1
Share this question
or