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

RowStyleSelector and GridViewComboBoxColumn

5 Answers 135 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 31 Aug 2011, 02:49 PM
Hello,

I followed this article and this article to conditionally style rows based on EntityState values.  I have noticed that this works great, except for GridViewComboBox columns.  My conditional styles include ForeGround, Background and FontStyle settings.  On the GridViewComboBox columns, only the BackGround and FontStyle settings are applied.  The ForeGround setting appears to be ignored.  Is there some element that I am missing with respect to the combobox column? 

Thanks.

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 03 Sep 2011, 12:39 PM
Hello Alex,

May you paste some relevant code , so we can try debug and  see what went wrong ?

Kind regards,
Pavel Pavlov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Alex
Top achievements
Rank 1
answered on 20 Sep 2011, 04:30 PM
Hello Pavel,

I was in the process of putting together a sample to reproduce the issue and realized that if I used the ItemsSourceBinding property of the column, then the style selector is applied as expected.  Previously I was binding to the ItemsSource in codebehind.  So it appears that at the time I was missing something to do with the ComboBoxColumn.

Anyway, thanks for your quick response and apologies for my late one.

Alex.
0
Nagisa
Top achievements
Rank 1
answered on 09 Mar 2012, 01:43 AM
Hi Admin,

I have the same problem that Foreground is not applied to GridViewComboBoxColumn when I using RowStyleSelector.
And I tried to bind ItemsSource with "ItemsSourceBinding".
The style of Foreground  is applied only data is loaded or scrolling data,
but it do not work when I turning page.
The style wasn't changed (as the same as previous page).
However,Background worked fine, and other columns worked as expected.

I paste my code segment following. 
Is there any wrong with my code?



Code of XMAL:

<Grid.Resources>
            <Style x:Key="Unfixed" TargetType="telerik:GridViewRow" />
            <Style x:Key="Fixed" TargetType="telerik:GridViewRow" >
                <Setter Property="Foreground" Value="#FF909090" />
            </Style>
 
            <styleSelector:FixStatusConverter x:Key="FixStatusConverter" />
 
            <styleSelector:ConditionalStyleSelector x:Key="FixStatusStyleSelector" ConditionConverter="{StaticResource FixStatusConverter}">
                <styleSelector:ConditionalStyleSelector.Rules>
                    <styleSelector:ConditionalStyleRule Style="{StaticResource Fixed}" Value="True"/>
                    <styleSelector:ConditionalStyleRule Style="{StaticResource Unfixed}" Value="False"/>
                </styleSelector:ConditionalStyleSelector.Rules>
            </styleSelector:ConditionalStyleSelector>
</Grid.Resources>
...
<telerik:RadDataPager x:Name="RadDataPager" Source="{Binding Items, ElementName=GridView}" NumericButtonCount="7" IsTotalItemCountFixed="True" DisplayMode="All" ... />
...
<telerik:RadGridView  x:Name="GridView" RowStyleSelector="{StaticResource FixStatusStyleSelector}" ...>
...
<telerik:GridViewComboBoxColumn UniqueName="PurClassID" DisplayMemberPath="PurClassName" SelectedValueMemberPath="PurClassID" DataMemberBinding="{Binding PurClassID}"
                                                        ItemsSourceBinding="{Binding PurClassList, Source={StaticResource PurClassListProvider}}" IsReadOnly="True"/>
....

Code of PurClassListProvider:

public class PurClassListProvider
{
 
    private List<PurClass> purClassList ;
 
    public PurClassListProvider()
    {
        ... // Create purClassList by using DomainContext
    }
     
    private void GetPurClasses_Completed(object sender, EventArgs e)
    {
        ... // Set purClassList using values obtained from server
    }
 
    public List<PurClass> PurClassList
    {
        get
        {
            return purClassList;
        }
    }
}
 
public class PurClass
{
    public string PurClassID {get; set;}
    public string PurClassName {get;set;}
}

Best regards,
Niwa
0
Siddhart
Top achievements
Rank 1
answered on 07 May 2013, 06:12 AM
Hey Pavel,

I am looking for the RowStyleSupport for my Project for which i am continously try to figure out how to fix row color on certain values i insert in it using converter for here i am adding my converter with xaml and codebehind using Viewmodel,
Could you please assist us how to provide row selector on certain values, Here am trying to get rowcolor orange when ClientStatus is Existing and IsValid column is false.

Here i am using constants for Clients status when ever these values passed orange color will return through converter, now i am looking how to to apply rowstyle selector on View and CodeBehind.

Please Look into it.
Thanks

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Globalization;
 
namespace TaxReporting.Modules.Converters
{
    public class GridRowColorConverter : IValueConverter
    {
 
        public object Convert(object value, Type targetType, object parameter,
                              CultureInfo culture)
        {
            switch (value.ToString())
            {
                case "": // Error
                    return parameter;
                case "0": // Error
                    return parameter;      // no color change it will remain the default color of the row
 
                default:
                    return "#C8DAC4"; // Green Color when archive version other then "0" or empty string
            }
        }
 
 
        public object ConvertBack(object value, Type targetType, object parameter,
 
 
                                          CultureInfo culture)
        {
            /* No Implementation for convert back as its one way binding   */
            return null;
        }
    }
 
}
<UserControl x:Class="TaxReporting.Modules.Views.ReportPaymentLoanIQCurrentYearView"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"          
    xmlns:local="clr-namespace:TaxReporting.Modules"
    xmlns:conv="clr-namespace:TaxReporting.Modules.Converters"            
    xmlns:sys="clr-namespace:System;assembly=mscorlib"        
    mc:Ignorable="d"
      d:DesignHeight="660" d:DesignWidth="440"
    xmlns:my="clr-namespace:TaxReporting.Modules.Views"
    xmlns:data="clr-namespace:TaxReporting.Modules.ViewModels"
    xmlns:telerikGrp="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"
    xmlns:type="clr-namespace:System;assembly=mscorlib"
             >
 
 
 
 
    <UserControl.Resources>
        <!--<conv:GridRowClientStatusColorConverter x:Key="GridRowClientStatusColorConverter"/>
        <Style x:Key="GridViewStyle" TargetType="telerik:GridViewRow">
            <Setter Property="Background" Value="Orange" />
             </Style>-->
             
             
            
 
 
 
 
 
            <!--<Style x:Key="NewStyle"
                   TargetType="telerik:GridViewRow"
                   BasedOn="{StaticResource GridViewRowStyle}">
                    <Setter Property="Background"
                        Value="{StaticResource AccentBrush}" />
                    <Setter Property="Foreground"
                        Value="{StaticResource MainBrush}" />
                </Style>
                <Style x:Key="ExistingStyle"
                   TargetType="telerik:GridViewRow"
                   BasedOn="{StaticResource GridViewRowStyle}" />-->
         
                <!--<conv:GridRowClientStatusColorConverter x:Key="converter"  />-->
                 
                <!--<UserControl.Resources:ConditionalStyleSelector   x:Key="selector"
                                               ConditionConverter="{StaticResource converter}">
                    <UserControl:ConditionalStyleSelector.Rules>
                        <UserControl:ConditionalStyleRule Style="{StaticResource NewStyle}">
                            <UserControl:ConditionalStyleRule.Value>
                                <sys:Boolean>True</sys:Boolean>
                            </UserControl:ConditionalStyleRule.Value>
                        </UserControl:ConditionalStyleRule>
                        <UserControl:ConditionalStyleRule Style="{StaticResource ExistingStyle}">
                            <UserControl:ConditionalStyleRule.Value>
                                <sys:Boolean>False</sys:Boolean>
                            </UserControl:ConditionalStyleRule.Value>
                        </UserControl:ConditionalStyleRule>
                    </UserControl:ConditionalStyleSelector.Rules>
                </UserControl:ConditionalStyleSelector>-->
       
    
 
        <!--<conv:GridRowClientStatusColorConverter x:Key="GridRowClientStatusColorConverter"/>-->
    
        
 
 
    </UserControl.Resources>
 
 
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.Resources>
            <!--<conv:GridRowClientStatusColorConverter x:Key="Converter"/>
            < x:Key="selector" ConditionConverter="{StaticResource Converter}">
                 
                 
                 
                 
            </Examples:ConditionalStyleSelector>-->
 
        </Grid.Resources>
 
       
 
 
 
 
 
        <Grid.RowDefinitions>
            <!--<RowDefinition  Height="1*"/>-->
            <RowDefinition  Height="50*"/>
            <RowDefinition  Height="4*"/>
        </Grid.RowDefinitions>
        
 
        <telerik:RadGridView   Name="dgridPayment"   IsReadOnly="True" RowLoaded="dgridPayment_RowLoaded" Style="{StaticResource GridViewStyle}"
                              CanUserFreezeColumns="False"   RowIndicatorVisibility="Collapsed"   AutoGenerateColumns="False"
                              Grid.Row="0" Margin="4"     AreRowDetailsFrozen="False" ShowGroupPanel="True" 
                        ItemsSource="{Binding PaymentDataList, Mode=TwoWay}"  Sorting="dgridPayment_Sorting"
          
                            >
 
            <i:Interaction.Behaviors>
 
                <local:ConditionalCellFormatting />
 
 
            </i:Interaction.Behaviors>
 
 
            <!--ItemsSource="{Binding ElementName=LayoutRoot,Path=DataContext.PageCollection, Mode=TwoWay}"-->
            <!--<telerik:RadGridView.SortDescriptors>
                    <telerik:SortDescriptor  SortDirection="Descending" />
                </telerik:RadGridView.SortDescriptors>-->
            <telerik:RadGridView.Columns>
                <!--<dxg:GridColumn AllowResizing="Auto" ColumnFilterMode="DisplayText" AllowSorting="True" Width="Auto" Header="DEAL RID"  Binding="{Binding DEAL_RID}"/>
                <dxg:GridColumn AllowResizing="Auto" ColumnFilterMode="DisplayText" AllowSorting="True" Width="Auto"  Header="DEAL NAME" Binding="{Binding DEAL_NAME}" />
                <dxg:GridColumn AllowResizing="Auto" ColumnFilterMode="DisplayText" AllowSorting="True" Width="Auto" Header="FACILTY RID"  Binding="{Binding FACILTY_RID}"/>-->
                <telerik:GridViewDataColumn     Header="LENDER FULL NAME" DataMemberBinding="{Binding LENDER_FULL_NAME}" />
                <telerik:GridViewDataColumn     Header="LENDER RID" DataMemberBinding="{Binding LENDER_RID}" />
                <telerik:GridViewDataColumn     Header="LENDER CIS"  DataMemberBinding="{Binding LENDER_CIS}"/>
                <telerik:GridViewDataColumn     Header="DEAL NAME" DataMemberBinding="{Binding DEAL_NAME}" />
                <telerik:GridViewDataColumn    Header="DEAL PID"     DataMemberBinding="{Binding DEAL_PID}" />
                <telerik:GridViewDataColumn    Header="PAYMENT TYPE" DataMemberBinding="{Binding PAYMENT_TYPE}"/>
                <telerik:GridViewDataColumn    IsSortable="True" Header="AMOUNT PAID(USD)" x:Name="AMOUNT_PAID_STR"  DataMemberBinding="{Binding AMOUNT_PAID}" />
                 
                <telerik:GridViewDataColumn    Header="BORROWER COUNTRY"     DataMemberBinding="{Binding BORROWER_COUNTRY}" />
                <telerik:GridViewDataColumn      Header="LENDER COUNTRY" DataMemberBinding="{Binding LENDER_COUNTRY}"/>
                <telerik:GridViewDataColumn     IsGroupable="True" IsFilterable="True" IsSortable="True"   Header="CLIENT STATUS"  DataMemberBinding="{Binding CLIENT_STATUS}" />
                <telerik:GridViewDataColumn    Header="BENEFICIARY NAME" DataMemberBinding="{Binding BENEFICIAL_OWNER_NAME}"/>
                <telerik:GridViewDataColumn      Header="FORM TYPE" DataMemberBinding="{Binding FORM_TYPE}" />
                <telerik:GridViewDataColumn    Header="IS VALID"     DataMemberBinding="{Binding IS_VALID}" />
                <telerik:GridViewDataColumn    Header="IS LIGHT PROCESS VALID"     DataMemberBinding="{Binding IS_LIGHT_PROCESS_VALID}" />
                <telerik:GridViewDataColumn      Header="RecCount" DataMemberBinding="{Binding RecCount}" />
                <telerik:GridViewDataColumn      Header="LOAD DATE" DataMemberBinding="{Binding LOAD_DATE}" />
                 
                <!--<telerik:GridViewDataColumn     Header="AGENT NAME"  DataMemberBinding="{Binding AGENT_NAME}"/>
                <telerik:GridViewDataColumn     Header="PAYMENT LOCATION" DataMemberBinding="{Binding PAYMENT_LOCATION}"/>
                <telerik:GridViewDataColumn     Header="LOCATION TAX ID" DataMemberBinding="{Binding LOCATION_TAX_ID}"/>
                <telerik:GridViewDataColumn     Header="PROFILE TAX ID" DataMemberBinding="{Binding PROFILE_TAX_ID}" />
                <telerik:GridViewDataColumn      Header="ADDRESS1"  DataMemberBinding="{Binding ADDRESS1}"/>
                <telerik:GridViewDataColumn      Header="ADDRESS2" DataMemberBinding="{Binding ADDRESS2}"/>
                <telerik:GridViewDataColumn      Header="ADDRESS3"  DataMemberBinding="{Binding ADDRESS3}"/>
                <telerik:GridViewDataColumn      Header="ADDRESS4" DataMemberBinding="{Binding ADDRESS4}" />
                <telerik:GridViewDataColumn      Header="CITY" DataMemberBinding="{Binding CITY}"/>
                <telerik:GridViewDataColumn      Header="STATE" DataMemberBinding="{Binding STATE}" />
                <telerik:GridViewDataColumn      Header="ZIP CODE"  DataMemberBinding="{Binding ZIP_CODE}"/>
                <telerik:GridViewDataColumn      Header="LENDER COUNTRY CODE" DataMemberBinding="{Binding LENDER_COUNTRY_CODE}" />     
                <telerik:GridViewDataColumn    Header="IS VALID"     DataMemberBinding="{Binding IS_VALID}" />-->
                 
                
            </telerik:RadGridView.Columns>
 
 
 
            <!--<telerik:TableView AutoWidth="False" AllowEditing="True"  AllowSorting="True"
                                           EditorButtonShowMode="ShowAlways" ShowGroupPanel="False"
                                           
                                           AllowHorizontalScrollingVirtualization="True"
                                           MultiSelectMode="Row"
                                            >
                    
                </dxg:TableView>-->
 
 
 
        </telerik:RadGridView >
 
        <telerik:RadDataPager  x:Name="RadDataPager" PageSize="25"    AutoEllipsisMode="Both"   Grid.Row="1"  Source="{Binding Items,ElementName=dgridPayment, Mode=TwoWay}"  IsTotalItemCountFixed="False"   HorizontalAlignment="Center" VerticalAlignment="Top"  />
        <!--<StackPanel Orientation="Horizontal" FlowDirection="RightToLeft" Grid.Row="1">
 
 
        </StackPanel>-->
 
 
        
             
            <!--<telerik:RadButton Content="Export" Command="{Binding ExportCommand, Source={StaticResource context}}"
                               CommandParameter="{Binding}"
                               Margin="0,10,0,0"/>-->
             
            
      
            <!--<telerik:Label  ToolTipService.ToolTip="Save to Excel" Background="white" VerticalAlignment="Center" Cursor="Hand">
                <Image x:Name="saveExcel" Source="../../ToolbarModule/images/icons/excel.png"  Width="35" Height="35" >
                    
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="MouseLeftButtonUp">
                            <i:InvokeCommandAction  Command="{Binding SaveToExcelCommand}" CommandParameter="{Binding ElementName=dgridPayment}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
                </Image>
                 
            </telerik:Label>-->
            <StackPanel Orientation="Horizontal" FlowDirection="RightToLeft" Grid.Row="1">
            <telerik:RadButton Name="Button1" Background="Chartreuse" ToolTipService.ToolTip="Save To Excel" Cursor="Hand" Click="Button1_Click_1" Content="Excel Export" Width="75" Height="35" Grid.Row="1">
 
            </telerik:RadButton>
 
        </StackPanel>
        <StackPanel Grid.Row="0" Visibility="{Binding LoadingImageVisibility}"      
        x:Name="parentCanvas"  HorizontalAlignment="Center"    VerticalAlignment="Center" 
        Background="White">
            <StackPanel Height="93" Width="63">
                <TextBlock x:Name="uxStatus" Height="25"  Text="Loading..." TextWrapping="Wrap" />
                <Grid x:Name="LoadingGrid" Background="White">
                    <Grid.RenderTransform>
                        <ScaleTransform x:Name="SpinnerScale" ScaleX="0.5" ScaleY="0.5" />
                    </Grid.RenderTransform>
                    <Grid>
                        <Canvas RenderTransformOrigin="0.5,0.5" Width="120" Height="120">
                            <Ellipse Width="21.835" Height="21.862" Canvas.Left="20.1696" Canvas.Top="9.76358"             Stretch="Fill" Fill="#E6000000"/>
                            <Ellipse Width="21.835" Height="21.862" Canvas.Left="2.86816" Canvas.Top="29.9581"             Stretch="Fill" Fill="#CD000000"/>
                            <Ellipse Width="21.835" Height="21.862" Canvas.Left="5.03758e-006" Canvas.Top="57.9341"        Stretch="Fill" Fill="#B3000000"/>
                            <Ellipse Width="21.835" Height="21.862" Canvas.Left="12.1203" Canvas.Top="83.3163"             Stretch="Fill" Fill="#9A000000"/>
                            <Ellipse Width="21.835" Height="21.862" Canvas.Left="36.5459" Canvas.Top="98.138"              Stretch="Fill" Fill="#80000000"/>
                            <Ellipse Width="21.835" Height="21.862" Canvas.Left="64.6723" Canvas.Top="96.8411"             Stretch="Fill" Fill="#67000000"/>
                            <Ellipse Width="21.835" Height="21.862" Canvas.Left="87.6176" Canvas.Top="81.2783"             Stretch="Fill" Fill="#4D000000"/>
                            <Ellipse Width="21.835" Height="21.862" Canvas.Left="98.165" Canvas.Top="54.414"               Stretch="Fill" Fill="#34000000"/>
                            <Ellipse Width="21.835" Height="21.862" Canvas.Left="92.9838" Canvas.Top="26.9938"             Stretch="Fill" Fill="#1A000000"/>
                            <Ellipse Width="21.835" Height="21.862" Canvas.Left="47.2783" Canvas.Top="0.5"                 Stretch="Fill" Fill="#FF000000"/>
                            <Canvas.RenderTransform>
                                <RotateTransform x:Name="SpinnerRotate" Angle="0" />
                            </Canvas.RenderTransform>
                            <Canvas.Triggers>
                                <EventTrigger RoutedEvent="ContentControl.Loaded">
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="SpinnerRotate"                                 
                                                             Storyboard.TargetProperty="(RotateTransform.Angle)"                                 
                                                             From="0" To="360" Duration="0:0:01"                                 
                                                             RepeatBehavior="Forever" />
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                            </Canvas.Triggers>
                        </Canvas>
                    </Grid>
                </Grid>
            </StackPanel>
        </StackPanel>
    </Grid>
 
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Data;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using System.Windows.Shapes;
using TaxReporting.Modules.ViewModels;
using Telerik.Windows.Controls;
using TaxReporting.Modules.ReportingService;
using System.IO;
using System.Windows.Interactivity;
using Telerik.Windows.Controls.GridView;
using System.Windows.Data;
using TaxReporting.Modules.Converters;
 
 
namespace TaxReporting.Modules.Views
{
    public partial class ReportPaymentLoanIQCurrentYearView : UserControl, IView
    {
 
 
        public ReportPaymentLoanIQCurrentYearView()
        {
 
 
            InitializeComponent();
 
            ViewModel = ObjectPool.GetObject<ReportPaymentLoanIQCurrentYearViewModel>();
           
            (this.dgridPayment.Columns["AMOUNT_PAID"] as GridViewDataColumn).DataType = typeof(decimal);
            this.DataContext = ViewModel;
 
 
        }
 
 
 
        public BaseViewModel ViewModel { get; set; }
 
        void ReportPaymentLoanIQCurrentYearView_Loaded(object sender, RoutedEventArgs e)
        {
 
            this.dgridPayment.ItemsSource = (ViewModel as ReportPaymentLoanIQCurrentYearViewModel).PaymentDataList;
        }
 
 
 
        private void dgridPayment_Sorting(object sender, GridViewSortingEventArgs e)
        {
            if (!e.Column.UniqueName.Equals("AMOUNT_PAID"))
                return;
            IList<PaymentDataLoanIQNxtYr> values = ((TaxReporting.Modules.ViewModels.ReportPaymentLoanIQCurrentYearViewModel)(e.DataControl.DataContext)).PaymentDataList;
            //e.DataControl.DataContext as List<CurrentPaymentDataLoanIQInFormat>;
            if (values == null)
            {
                e.Cancel = true;
                return;
            }
 
            if (e.OldSortingState == SortingState.None)
            {
                e.NewSortingState = SortingState.Ascending;
                values = values.OrderBy(v => Convert.ToDecimal(v.AMOUNT_PAID)).ToList();
 
            }
            //If the sorting state is ascending, sort the items descending. 
            else if (e.OldSortingState == SortingState.Ascending)
            {
                e.NewSortingState = SortingState.Descending;
                values = values.OrderByDescending(v => Convert.ToDecimal(v.AMOUNT_PAID)).ToList();
 
            }
            //If the sorting state is descending, apply default sorting to the items. 
            else
            {
                e.NewSortingState = SortingState.None;
                //values = values.OrderBy(v => Convert.ToDecimal(v.AMOUNT_PAID)).ToList();
            }
            e.DataControl.ItemsSource = values.ToList();
            e.Cancel = true;
        }
 
 
 
        public class ConditionalStyleSelectorConverter : StyleSelector
        {
            public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject container)
            {
                object conditionValue = this.ConditionConverter.Convert(item, null, null, null);
                foreach (ConditionalStyleRule rule in this.Rules)
                {
                    if (Equals(rule.Value, conditionValue))
                    {
                        return rule.Style;
                    }
                }
 
                return base.SelectStyle(item, container);
            }
 
            List<ConditionalStyleRule> _Rules;
            public List<ConditionalStyleRule> Rules
            {
                get
                {
                    if (this._Rules == null)
                    {
                        this._Rules = new List<ConditionalStyleRule>();
                    }
 
                    return this._Rules;
                }
            }
 
            IValueConverter _ConditionConverter;
            public IValueConverter ConditionConverter
            {
                get
                {
                    return this._ConditionConverter;
                }
                set
                {
                    this._ConditionConverter = value;
                }
            }
        }
 
        public class ConditionalStyleRule
        {
            object _Value;
            public object Value
            {
                get
                {
                    return this._Value;
                }
                set
                {
                    this._Value = value;
                }
            }
 
            Style _Style;
            public Style Style
            {
                get
                {
                    return this._Style;
                }
                set
                {
                    this._Style = value;
                }
            }
        }
 
 
 
        private void Button1_Click_1(object sender, RoutedEventArgs e)
        {
            string extension = "xls";
            SaveFileDialog dialog = new SaveFileDialog()
            {
                DefaultExt = extension,
                Filter = String.Format("{1} files (*.{0})|*.{0}|All files(*.*)|*.*", extension, "Excel"),
                FilterIndex = 1
            };
            if (dialog.ShowDialog() == true)
            {
                using (Stream stream = dialog.OpenFile())
                {
                    dgridPayment.Export(stream,
                     new GridViewExportOptions()
                     {
                         Format = ExportFormat.ExcelML,
                         ShowColumnFooters = true,
                         ShowColumnHeaders = true,
                         ShowGroupFooters = false,
                     });
                }
            }
        }
 
 
 
 
      
 
       public class ConditionalFormattingBehavior : Behavior<RadGridView>
 
       {
 
          protected override void OnAttached()
 
 
       {
 
            base.OnAttached();
 
 
            this.AssociatedObject.RowLoaded += new EventHandler<Telerik.Windows.Controls.GridView.RowLoadedEventArgs>(AssociatedObject_RowLoaded);
 
       }
 
     
 
 
       }
 
 
       void AssociatedObject_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
 
       {
 
           if ((e.Row is GridViewHeaderRow) || (e.Row is GridViewFooterRow) || (e.Row is GridViewNewRow))
 
               return;
 
 
           Binding colorBinding = new Binding("CLIENT_STATUS") { Converter = new GridRowClientStatusColorConverter() };
 
           e.Row.Cells[1].SetBinding(GridViewRow.ForegroundProperty, colorBinding);
 
 
 
       }
        
 
 
    }
}
 
 
        
 
 
       
             
        
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using TaxReporting.CommonFE;
using TaxReporting.Modules.LoggingService;
using TaxReporting.Modules.Model.Events;
using TaxReporting.Modules.ReportingService;
using System.Windows.Data;
using System.Collections.ObjectModel;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;
using Telerik.Windows.Input;
 
 
 
 
namespace TaxReporting.Modules.ViewModels
{
    public class ReportPaymentLoanIQCurrentYearViewModel : BaseViewModel
    {
        #region Private Variables
 
        ReportingService.ReportingServiceClient reportingService;
        LoggingServiceFEClient loggingService;
 
        private const string MSG_RPT_SERVICE_DATA_EXCEPTION = "Some error has occurred while processing your request. Please contact the Support team.";
 
 
        #endregion
 
        #region Public variables
 
        //public IList<CurrentPaymentDataLoanIQInFormat> PaymentDataList { get; set; }
        public ObservableCollection<PaymentDataLoanIQNxtYr> PaymentDataList { get; set; }
 
        public ICommand SaveToExcelCommand { get; set; }
        //public ICommand ExportCommand { get; set; }
 
 
        public object RadDataPager { get; set; }
        private PagedCollectionView _PageCollection;
        public PagedCollectionView PageCollection
        {
            get { return _PageCollection; }
            set
            {
                if (_PageCollection != value)
                {
                    _PageCollection = value;
                    OnPropertyChange("PageCollection");
                }
            }
        }
 
 
        public bool IsInDesignMode
        {
            get { return (Application.Current == null) || (Application.Current.GetType() == typeof(Application)); }
        }
 
        Visibility _LoadingImageVisibility;
        public Visibility LoadingImageVisibility
        {
            get { return _LoadingImageVisibility; }
            set
            {
                _LoadingImageVisibility = value;
                OnPropertyChange("LoadingImageVisibility");
            }
        }
 
        #endregion
 
        #region Constructors
 
        public ReportPaymentLoanIQCurrentYearViewModel()
        {
            if (!this.IsInDesignMode)
            {
                reportingService = new ReportingServiceClient();
                loggingService = new LoggingServiceFEClient();
                //GridDataSource = null;
                //OnPropertyChange("GridDataSource");
                Utils.GetEventAggregator().GetEvent<ViewPaymentEvent>().Subscribe(ViewPayment);
                //SaveToExcelCommand = new TaxReporting.CommonFE.DelegateCommand(SaveToExcel, SaveToExcelCanExecute);
                reportingService.GetPaymentDataLoanIQNxtYrCompleted += (sender, e) =>
                {
                    try
                    {
                        LoadingImageVisibility = Visibility.Collapsed;
                        PaymentDataList = new ObservableCollection<PaymentDataLoanIQNxtYr>();
 
                        OnPropertyChange("PaymentDataList");
                        OnPropertyChange("AMOUNT_PAID");
                        PageCollection = default(PagedCollectionView);
                        IList<PaymentDataLoanIQNxtYr> result = e.Result as IList<PaymentDataLoanIQNxtYr>;
                        //if (result.Count == 0) return;
                        foreach (PaymentDataLoanIQNxtYr paymentData in result)
                        {
                            PaymentDataList.Add(paymentData);
 
                        }
 
                        PageCollection = new PagedCollectionView(PaymentDataList);
 
                        OnPropertyChange("PageCollection");
                        OnPropertyChange("PaymentDataList");
                        //GridDataSource = DevExpress.Xpf.Core.Native.DataBindingHelper.ExtractDataSourceFromCollectionView(PageCollection);
                        //OnPropertyChange("GridDataSource");
 
                    }
 
                    catch (Exception ex)
                    {
                        LoadingImageVisibility = Visibility.Collapsed;
                        LogException(UserID, ex.Message, ex.ToString());
                        MessageBox.Show(MSG_RPT_SERVICE_DATA_EXCEPTION);
                        throw;
                    }
                };
 
                loggingService.LogFrontEndExceptionsCompleted += (sender, e) =>
                {
                };
            }
            else
            {
                PaymentDataList = new ObservableCollection<PaymentDataLoanIQNxtYr>();
 
            }
        }
 
        #endregion
 
 
 
        //public class ExportCommand : ICommand
        //{
 
        //    private readonly ExportingModel model;
 
        //    public ExportCommand(ExportingModel model)
        //    {
        //        this.model = model;
        //    }
 
        //    public bool CanExecute(object parameter)
        //    {
        //        return true;
        //    }
 
        //    public event EventHandler CanExecuteChanged;
 
        //    public void Execute(object parameter)
        //    {
        //        this.model.Export(parameter);
        //    }
 
 
        //    public class ExportingModel : ViewModelBase
        //    {
        //        public ExportingModel()
        //        {
        //            this.ExportCommand = new ExportCommand(this);
        //        }
 
        //        private ExportCommand exportCommand = null;
 
        //        public ExportCommand ExportCommand
        //        {
        //            get
        //            {
        //                return this.exportCommand;
        //            }
        //            set
        //            {
        //                if (this.exportCommand != value)
        //                {
        //                    this.exportCommand = value;
        //                    OnPropertyChanged("ExportCommand");
        //                }
        //            }
        //        }
 
 
 
        //        IEnumerable<string> exportFormats;
        //        public IEnumerable<string> ExportFormats
        //        {
        //            get
        //            {
        //                if (exportFormats == null)
        //                {
        //                    exportFormats = new string[] { "Excel", "ExcelML", "Word", "Csv" };
        //                }
 
        //                return exportFormats;
        //            }
        //        }
 
        //        string selectedExportFormat;
        //        public string SelectedExportFormat
        //        {
        //            get
        //            {
        //                return selectedExportFormat;
        //            }
        //            set
        //            {
        //                if (!object.Equals(selectedExportFormat, value))
        //                {
        //                    selectedExportFormat = value;
 
        //                    OnPropertyChanged("SelectedExportFormat");
        //                }
        //            }
        //        }
 
        //     }
 
 
        #region Public Methods
 
        //public void SaveToExcel(object parameter)
        //{
        //    RadGridView dg = parameter as RadGridView;
 
        //    Utils.SaveToExcel(PaymentDataList, dg, "LENDER_CIS", "LENDER_RID", "ZIP_CODE");
        //}
 
        //public bool SaveToExcelCanExecute(object parameter)
        //{
        //    return true;
        //}
 
 
 
 
 
        public void ViewPayment(ReportPayLoad payLoad)
        {
            if (payLoad == null) return;
            if (string.Compare(payLoad.systemName.ToUpper(), SettlementSystemType.LOANIQ.ToString(), System.StringComparison.CurrentCultureIgnoreCase) != 0) return;
            if (string.IsNullOrWhiteSpace(payLoad.Year)) return;
            if (reportingService == null)
                reportingService = new ReportingServiceClient();
            LoadingImageVisibility = Visibility.Visible;
            reportingService.GetPaymentDataLoanIQNxtYrAsync(payLoad.systemName, payLoad.Year);
        }
 
        #endregion
 
 
        #region Private Methods
 
        private void LogException(string userID, string message, string details)
        {
            if (loggingService == null)
                loggingService = new LoggingServiceFEClient();
 
            loggingService.LogFrontEndExceptionsAsync(userID, message, details);
        }
 
        #endregion
 
    }
    }
0
Pavel Pavlov
Telerik team
answered on 09 May 2013, 10:54 AM
Hello,

You can create a rowstyle selector of yours and set it for the rows - something like :

public class MyStyleSelector : StyleSelector
    {
        public override Style SelectStyle(object item, DependencyObject container)
        {
            Style style = new Style();
            style.TargetType = typeof(GridViewRow);
             
            Brush brush = null;
            if (!((MyItem)item).IsValid && ((MyItem)item).ClientStatus == "Existing")
            {
                brush = new SolidColorBrush(Colors.Orange);
            }
            else
            {
                brush = new SolidColorBrush(Colors.Transparent);
            }
            style.Setters.Add(new Setter(Control.BackgroundProperty,brush));
            return style;
        }
    }
for illustrative purposes this code is based on the following simpidfied data item :

public class MyItem

{

public string ClientStatus { get; set; }

public bool IsValid { get; set; }

}

* You will have to adapt it to your data items a little bit.


Regards,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Alex
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Alex
Top achievements
Rank 1
Nagisa
Top achievements
Rank 1
Siddhart
Top achievements
Rank 1
Share this question
or