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

Change GridViewRow text color when modifications are made

18 Answers 492 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Stefan Buys
Top achievements
Rank 2
Stefan Buys asked on 14 Sep 2010, 02:49 PM
Hi,

I have a RadGridView which is bound to a DomainDataSource (RIA Services). The User is be able to Add, Edit, Clone and Delete rows. The DomainDataSource helps me keep track of the entity changes, but I would like to also "keep track" visually in the grid. In other words, I would like to change the text color of the entire row for each action the user performs. In case of an Add, the text color must be blue, in case of an Edit, it must be green, etc.

I have tried applying a StyleSelector via the RowStyleSelector property (As per Telerik Documentation), but it doesn't appear to update after User actions occured.

Is there a way to access it each Row and apply a given style to it? Or is there an alternative way to handle this?

Please advise,
Stefan Buys

18 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 14 Sep 2010, 03:51 PM
Hello Stefan Buys,

Please check this blog post for an example and source code:
Displaying live streaming data with RadGridView for Silverlight and WPF

Sincerely yours,
Veselin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stefan Buys
Top achievements
Rank 2
answered on 15 Sep 2010, 04:02 PM
Hi Veselin,

The blog post you referred me to shows how the CellTemplate associated to each column within the row gets updated dynamically from the underlying ItemsSource. I want to avoid updating each column's CellTemplate within the row. I simply want to be able to update a common property of the entire row. For instance, I subscribed to the RowEditEnded event handler which exposes a GridViewRow and was able to simply perform:

...
if (((UsersEntity)e.Row.Item).EntityState == EntityState.New)
    e.Row.Foreground = new SolidColorBrush(Colors.Blue);


...
if (((UsersEntity)e.Row.Item).EntityState == EntityState.Modified)
    e.Row.Foreground = new SolidColorBrush(Colors.Green);


However, as soon as I inserted a new row, the previously updated/added rows's Foreground color resets. As a workaround, I tried looping through the Rows collection within the grid and set the Foreground color based on the Entity's state, but there appears to be no property that contains a collection of GridViewRows (similar to the GridViewColumnCollection). I even tried the above code in conjuction with a RowStyleSelector performing the same actions, but the Style updates occurs randomly and incorrectly.

Any further advice will be most welcome.

Stefan



0
Veselin Vasilev
Telerik team
answered on 16 Sep 2010, 04:18 PM
Hi Stefan Buys,

Please find attached a sample project.

It uses the Employees domain service to connect to the Employees table of the Northwind database.
I have added one additional field to the table - IsNew. I set it to True for every new created entity (look in the Employee.cs file in the Silverlight project). I have created a RowStyleSelector which changes the background for every item marked as new (IsNew = true).

I hope it will get you started.

All the best,
Veselin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bronwen
Top achievements
Rank 1
answered on 04 Nov 2010, 11:57 PM
Hi,
I wanted to use a rowstyleselector to set the colour of the grid column based on a property of my entity. I've done something very similar to your example and the colour displays fine.

I have a field called IsValid that I use to set the grid row selector that gets updated based on values in other fields. When I change the fields in the grid to make the record valid the IsValid the field updates in the grid but the rowselector doesn't change colour.

How do I reapply the row style when this gets modified?
0
Pavel Pavlov
Telerik team
answered on 05 Nov 2010, 10:13 AM
Hello Bronwen,

It should be enough to raise the PropertyChangedEvent (form the INotifyPropertyChanged Interface) when the IsValid field is changed. In case this does not do the trick , you may need to upgrade to a later version as in early version s of RadGridView StyleSelectors did not react on changes on-the-fly. Currently this is fixed and the INotifyPropertyChanged approach should do the trick .

Regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bronwen
Top achievements
Rank 1
answered on 05 Nov 2010, 11:14 PM
Hi,
I am firing a property change as you say and I'm running the latest service pack.
0
Vlad
Telerik team
answered on 09 Nov 2010, 11:31 AM
Hello,

 We've just fixed a bug related to this and the fix will be part of both our latest build and our Q3 2010 release. 

Greetings,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bronwen
Top achievements
Rank 1
answered on 11 Nov 2010, 12:30 AM
Hi, I've downloaded the Q3 release this morning and it's all working now. Thx.
0
Juliana
Top achievements
Rank 1
answered on 17 Feb 2011, 09:21 AM
Hello,

I downloaded the sample. And it works fine until I try to set AlternateRowBackground="Bisque" AlternationCount="2". In this case no style applies for alternate row. How can I avoid it?

Thanks,
Juliana
0
Pavel Pavlov
Telerik team
answered on 17 Feb 2011, 11:30 AM
Hi Juliana,

I am going to check the issue. Which example are you refering ?

Regards,
Pavel Pavlov
the Telerik team
0
Juliana
Top achievements
Rank 1
answered on 17 Feb 2011, 11:51 AM
Hello Pavel,

I meant ria-rowstyleselector.zip  by Veselin Vasilev. I changed control version to 2010.3.1110.1040, set AlternateRowBackground="Bisque" AlternationCount="2" and custom style disappeared for alternate rows.

Thanks,
Juliana
0
Ivan Ivanov
Telerik team
answered on 23 Feb 2011, 07:40 AM
Hi Bronwen,

 Since the AlternateRow style is applied after the styling of the other GridViewRows, it overrides the conditionally set styles of your StyleSelector. I am sending you a workaround that utilizes the StyleSelector to set  styles on your AlternationRows, instead of RadGridView's AlternationStyle logic. Please, let me know if this approach fits into you requirements.


Sincerely,

Ivan Ivanov
the Telerik team

 

Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Mark
Top achievements
Rank 1
answered on 17 Oct 2011, 05:35 PM
Trying to do something similar with RadControls for Silverlight v2011.2.920.1040. I want to make a row "busy" while making a WCF call. I want cells on a row to be editable and perform calculations based on user entry. But I want to set an "IsBusy" on the row level after the user changes a cell value until the correponding completed event (an IsBusy graphic would be even better). My problem is the RowSelector never fires again when the IsBusy value changes on the bound item. And yes, I am raising the PropertyChanged
event on that item's property. Below is my code:

---------------------------------------------------------
--StyleSelector
---------------------------------------------------------
using System.Windows;
 
using Telerik.Windows.Controls;
 
namespace CorporateBondCalculator
{
    public class RowIsBusyStyleSelector : StyleSelector
    {
        public Style IsBusyStyle  { get; set; }
        public Style DefaultStyle { get; set; }
 
        public override Style SelectStyle(object item, DependencyObject container)
        {
            if (item is MultiBondBackingStore.MultiBondItem)
            {
                MultiBondBackingStore.MultiBondItem multiBondItem = item as MultiBondBackingStore.MultiBondItem;
 
                if (multiBondItem.IsBusy)
                {
                    return IsBusyStyle;
                }
                else
                {
                    return DefaultStyle;
                }
            }
 
            return null;
        }
    }
}
 
---------------------------------------------------------
--Resource definition
---------------------------------------------------------
 
<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/CorporateBondCalculator;component/CBCResources.xaml" />
            <ResourceDictionary Source="/CorporateBondCalculator;component/MultiBond/MultiBondResource.xaml" />
        </ResourceDictionary.MergedDictionaries>
 
         <uc1:RowIsBusyStyleSelector x:Key="rowIsBusyStyleSelector">
 
            <uc1:RowIsBusyStyleSelector.IsBusyStyle>
                <Style TargetType="telerik:GridViewRow">
                    <Setter Property="Foreground" Value="Gray" />
                    <Setter Property="Background" Value="Gray" />
                    <Setter Property="IsEnabled"  Value="False" />
                </Style>
            </uc1:RowIsBusyStyleSelector.IsBusyStyle>
 
            <uc1:RowIsBusyStyleSelector.DefaultStyle>
                <Style TargetType="telerik:GridViewRow">
                    <Setter Property="Foreground" Value="White" />
                    <Setter Property="IsEnabled"  Value="True" />
                </Style>
            </uc1:RowIsBusyStyleSelector.DefaultStyle>
 
        </uc1:RowIsBusyStyleSelector>
 
    </ResourceDictionary>
</UserControl.Resources>
 
---------------------------------------------------------
--Grid Definition
---------------------------------------------------------
<telerikGV:RadGridView x:Name="BondGrid" Grid.Row="2" CanUserInsertRows="False" ShowInsertRow="False" FrozenColumnCount="4"
    converter:MultiBondGridContextMenu.IsEnabled="True"
    ScrollViewer.HorizontalScrollBarVisibility="Auto" IsReadOnly="False"
                                     
    SelectionMode="Extended" SelectionUnit="Cell" ClipboardPasteMode="Cells, Default"
    Pasted="BondGrid_Pasted" Pasting="BondGrid_Pasting" PastingCellClipboardContent="BondGrid_PastingCellClipboardContent"
                                        
    AutoGenerateColumns="False" Grid.Column="0" IsFilteringAllowed="False" ShowGroupPanel="False" CanUserReorderColumns="True"
    RowDetailsVisibilityMode="Collapsed"
    RowDetailsVisibilityChanged="BondGrid_RowDetailsVisibilityChanged"
    BeginningEdit="BondGrid_BeginningEdit"
    CellEditEnded="BondGrid_CellEditEnded"
    ElementExporting="BondGrid_ElementExporting" ElementExported="BondGrid_ElementExported"
    RowEditEnded="BondGrid_RowEditEnded" RowLoaded="BondGrid_RowLoaded"
    EnableColumnVirtualization="True"
    EnableRowVirtualization="True"
 
    RowStyleSelector="{StaticResource rowIsBusyStyleSelector}"
    >
0
Vlad
Telerik team
answered on 18 Oct 2011, 07:29 AM
Hello,

 Can you post your data item/IsBusy code?

All the best,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Mark
Top achievements
Rank 1
answered on 18 Oct 2011, 04:44 PM
public class MultiBondItem : INotifyPropertyChanged, IDisposable
{
private int isBusy;
public event PropertyChangedEventHandler PropertyChanged;
 
--Since there are multiple cells that could be edited, we "count" busy items to determine if the row is busy
public bool IsBusy
{
get
{
return isBusy   != 0;
}
set
{
bool wasBusy     = isBusy != 0;
 
if (value       == true)
isBusy++;
else
isBusy--;

if (wasBusy     != (isBusy != 0))
{
RaisePropertyChanged("IsBusy");
}
}
}
 
void RaisePropertyChanged(string propertyName, object sender = null)
{
if (sender          == null)
sender           = BackingStore.Trigger.UI;
 
if (PropertyChanged != null)
{
PropertyChanged(sender, new PropertyChangedEventArgs(propertyName));
}
}
}
0
Mark
Top achievements
Rank 1
answered on 19 Oct 2011, 10:41 PM
Any update? I see other issue posted about the StyleSelector not firing on property updates. Rebinding is not an option for me as it would clear some cells and kickoff other calculations.
0
Vlad
Telerik team
answered on 21 Oct 2011, 12:05 PM
Hello,

 I've attached an example project for reference. 

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Mark
Top achievements
Rank 1
answered on 21 Oct 2011, 07:51 PM
The SilverlightApplication1.csproj project cannot find the following referenced projects:

    <ProjectReference Include="..\..\..\..\Work\Development\Controls\GridView\GridView\GridView-SL.csproj">
      <Project>{435A1141-A324-422E-8548-749440B13F16}</Project>
      <Name>GridView-SL</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\..\..\Work\Development\Controls\Input\Input_SL.csproj">
      <Project>{8A31E9E3-3166-4F5C-BE42-B86115F18AAC}</Project>
      <Name>Input_SL</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\..\..\Work\Development\Core\Controls\Controls_SL.csproj">
      <Project>{7EE7B7BA-AB69-40AA-BC04-6C3528A1770B}</Project>
      <Name>Controls_SL</Name>
    </ProjectReference>
    <ProjectReference Include="..\..\..\..\Work\Development\Core\Data\Data_SL.csproj">

Tags
GridView
Asked by
Stefan Buys
Top achievements
Rank 2
Answers by
Veselin Vasilev
Telerik team
Stefan Buys
Top achievements
Rank 2
Bronwen
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Vlad
Telerik team
Juliana
Top achievements
Rank 1
Ivan Ivanov
Telerik team
Mark
Top achievements
Rank 1
Share this question
or