Change GridViewRow text color when modifications are made

19 posts, 0 answers
  1. Stefan Buys
    Stefan Buys avatar
    22 posts
    Member since:
    Dec 2009

    Posted 14 Sep 2010 Link to this post

    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

  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 14 Sep 2010 Link to this post

    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
  3. Stefan Buys
    Stefan Buys avatar
    22 posts
    Member since:
    Dec 2009

    Posted 15 Sep 2010 Link to this post

    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



  4. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 16 Sep 2010 Link to this post

    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
  5. Bronwen
    Bronwen avatar
    6 posts
    Member since:
    May 2009

    Posted 04 Nov 2010 Link to this post

    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?
  6. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 05 Nov 2010 Link to this post

    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
  7. Bronwen
    Bronwen avatar
    6 posts
    Member since:
    May 2009

    Posted 05 Nov 2010 Link to this post

    Hi,
    I am firing a property change as you say and I'm running the latest service pack.
  8. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 09 Nov 2010 Link to this post

    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
  9. Bronwen
    Bronwen avatar
    6 posts
    Member since:
    May 2009

    Posted 10 Nov 2010 Link to this post

    Hi, I've downloaded the Q3 release this morning and it's all working now. Thx.
  10. Juliana
    Juliana avatar
    71 posts
    Member since:
    Feb 2008

    Posted 17 Feb 2011 Link to this post

    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
  11. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 17 Feb 2011 Link to this post

    Hi Juliana,

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

    Regards,
    Pavel Pavlov
    the Telerik team
  12. Juliana
    Juliana avatar
    71 posts
    Member since:
    Feb 2008

    Posted 17 Feb 2011 Link to this post

    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
  13. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1216 posts

    Posted 23 Feb 2011 Link to this post

    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!
  14. Mark
    Mark avatar
    13 posts
    Member since:
    Aug 2012

    Posted 17 Oct 2011 Link to this post

    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}"
        >
  15. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 18 Oct 2011 Link to this post

    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 >>

  16. Mark
    Mark avatar
    13 posts
    Member since:
    Aug 2012

    Posted 18 Oct 2011 Link to this post

    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));
    }
    }
    }
  17. Mark
    Mark avatar
    13 posts
    Member since:
    Aug 2012

    Posted 19 Oct 2011 Link to this post

    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.
  18. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 21 Oct 2011 Link to this post

    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 >>

  19. Mark
    Mark avatar
    13 posts
    Member since:
    Aug 2012

    Posted 21 Oct 2011 Link to this post

    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">

Back to Top