Problem with RowStyleSelector

5 posts, 0 answers
  1. Start
    Start avatar
    12 posts
    Member since:
    Feb 2015

    Posted 25 Jul Link to this post

    Hi, I tried to follow the examples in this thead but I can't get it working. Can someone show me ho to set the backgroud of the rows where the columns Quantità and QtaPrelevata have the same value? 

    VB.net please. 

     

    <telerik:RadDataPager x:Name="rDataPager" PageSize="10" Source="{Binding Items, ElementName=gridOrdini}" ></telerik:RadDataPager>
                <telerik:RadGridView x:Name="gridOrdini" SelectionUnit="FullRow"  AutoGenerateColumns="False" CanUserInsertRows="False" CanUserDeleteRows="False" RowIndicatorVisibility="Collapsed"
            ShowGroupPanel="False" IsReadOnly="False" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" SelectionMode="Single" CanUserReorderColumns="False" 
                FontFamily="Source Sans Pro Semibold" FontSize="14" GridLinesVisibility="Horizontal" IsFilteringAllowed="False">
                    <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn x:Name="Vettore1" UniqueName="Vettore1" Header="Vettore" IsReadOnly="True" IsVisible="False" Width="60" DataMemberBinding="{Binding Vettore1}"/>
                        <telerik:GridViewDataColumn x:Name="Articolo" Header="Articolo" IsReadOnly="True" DataMemberBinding="{Binding Articolo}" Width="100"/>
                        <telerik:GridViewDataColumn x:Name="Descri" Header="Descri" IsReadOnly="True" DataMemberBinding="{Binding Descri}" Width="*"/>
                        <telerik:GridViewDataColumn x:Name="Quantita" Header="Quantità" IsReadOnly="True" DataMemberBinding="{Binding Quantita}" Width="80"/>
                        <telerik:GridViewDataColumn x:Name="QtaPrelevata" Header="Qta Prelevata" IsReadOnly="True" DataMemberBinding="{Binding QtaPrelevata}" Width="80"/>
                        <telerik:GridViewDataColumn x:Name="Reparto" Header="Reparto" IsReadOnly="True" DataMemberBinding="{Binding Reparto}" Width="80"/>
                        <telerik:GridViewDataColumn x:Name="UnMis" Header="UnMis" IsReadOnly="True" DataMemberBinding="{Binding UnMis}" Width="60"/>
                        <telerik:GridViewDataColumn x:Name="Cella" Header="Cella" IsReadOnly="True" DataMemberBinding="{Binding Cella}" Width="60"/>
                        <telerik:GridViewDataColumn x:Name="GruppoCella" Header="GruppoCella" IsReadOnly="True" DataMemberBinding="{Binding GruppoCella}" Width="80"/>
                        <telerik:GridViewDataColumn x:Name="CatMerc" Header="CatMerc" IsReadOnly="True" DataMemberBinding="{Binding CatMerc}" Width="80"/>
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>

     

    Thank you very mutch

  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    277 posts

    Posted 27 Jul Link to this post

    Hello,

    Please review the RowStyleSelector article from our documentation page - RowStyleSelectors. In the SelectStyle method for your RowStyleSelector, you need to compare the values of the two properties and in case they are the same to return a certain Style that would change the background of the row. You can check the Row Style Selector demo in our SDK Samples Browser as well.

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Start
    Start avatar
    12 posts
    Member since:
    Feb 2015

    Posted 29 Jul Link to this post

    Ok, so I had a look on the RowStyleSelector SDK Sample and I was trying to replicate it in my project.

    1- Added the <UserControl.Resources> in my UserControl

    2- Set the RowStyleSelector="{StaticResource stadiumCapacityStyle}" in my radGrid

    3- Created the StadiumCapacityStyle class.

    Now my xaml is this:

    <UserControl x:Class="PickingLists"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 xmlns:local="clr-namespace:Dalessio_Logistics"
                 xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
                 xmlns:sys="clr-namespace:System;assembly=mscorlib"
                 mc:Ignorable="d"
                 d:DesignHeight="500" d:DesignWidth="1100" Background="White">
     
        <UserControl.Resources>
            <local:StadiumCapacityStyle x:Key="stadiumCapacityStyle">
                <local:StadiumCapacityStyle.BigStadiumStyle>
                    <Style TargetType="telerik:GridViewRow">
                        <Setter Property="Background" Value="Red"/>
                    </Style>
                </local:StadiumCapacityStyle.BigStadiumStyle>
                <local:StadiumCapacityStyle.SmallStadiumStyle>
                    <Style TargetType="telerik:GridViewRow">
                        <Setter Property="Background" Value="Yellow" />
                    </Style>
                </local:StadiumCapacityStyle.SmallStadiumStyle>
            </local:StadiumCapacityStyle>
        </UserControl.Resources>
     
        <telerik:RadBusyIndicator x:Name="busyLoading" IsIndeterminate="True" BusyContent="Salvataggio inventario in corso...">
            <StackPanel x:Name="panelGridDocuments" Margin="0,0,0,0" Height="auto" HorizontalAlignment="Stretch">
             
                <StackPanel x:Name="panelFilters" Height="50" VerticalAlignment="Top" DockPanel.Dock="Top" Orientation="Horizontal" HorizontalAlignment="Stretch">
     
                    <telerik:Label Content="Data consegna:" Padding="5,3,5,3" BorderThickness="1,0,0,0" BorderBrush="#FFCCCCCC"/>
                    <telerik:RadDatePicker x:Name="rdpDataOrdini" BorderThickness="0,0,0,0" Margin="0,0,5,0" TodayButtonVisibility="Visible" TodayButtonContent="Oggi"/>
                    <RadioButton x:Name="radrbFresco" Content="Fresco" IsEnabled="False"/>
                    <RadioButton x:Name="radrbAltro" Content="Altro" IsEnabled="False"/>
                    <telerik:RadButton x:Name="btnUpdateVectors" Width="40" Height="40" Margin="15,5,10,5" VerticalAlignment="Center" BorderThickness="0" IsEnabled="False">
                        <Button.Background>
                            <VisualBrush>
                                <VisualBrush.Visual>
                                    <Canvas Clip="F1M0,0L76,0 76,76 0,76 0,0" Height="60" UseLayoutRounding="True" Width="60" d:DesignUseLayoutRounding="True">
                                        <Path Data="F1 M 38,20.5833C 42.9908,20.5833 47.4912,22.6825 50.6667,26.046L 50.6667,17.4167L 55.4166,22.1667L 55.4167,34.8333L 42.75,34.8333L 38,30.0833L 46.8512,30.0833C 44.6768,27.6539 41.517,26.125 38,26.125C 31.9785,26.125 27.0037,30.6068 26.2296,36.4167L 20.6543,36.4167C 21.4543,27.5397 28.9148,20.5833 38,20.5833 Z M 38,49.875C 44.0215,49.875 48.9963,45.3932 49.7703,39.5833L 55.3457,39.5833C 54.5457,48.4603 47.0852,55.4167 38,55.4167C 33.0092,55.4167 28.5088,53.3175 25.3333,49.954L 25.3333,58.5833L 20.5833,53.8333L 20.5833,41.1667L 33.25,41.1667L 38,45.9167L 29.1487,45.9167C 31.3231,48.3461 34.483,49.875 38,49.875 Z " Fill="#FF26A0DA" Canvas.Left="19" Stretch="Fill" Canvas.Top="18.9749" UseLayoutRounding="True" d:DesignUseLayoutRounding="True"/>
                                    </Canvas>
                                </VisualBrush.Visual>
                            </VisualBrush>
                        </Button.Background>
                    </telerik:RadButton>
                    <telerik:RadComboBox x:Name="rcbVettore" EmptyText="Scegli vettore" Margin="5,0,0,0" Height="40" Width="150" IsEnabled="False"/>
                    <telerik:RadButton x:Name="btnDownloadOrders" Width="150" Height="40" Content="Scarica ordini" Margin="40,5,10,5" VerticalAlignment="Center" IsEnabled="False" />
                    <CheckBox x:Name="cbMostraCompeli" Content="Completi" Checked="cbMostraCompeli_Checked" Unchecked="cbMostraCompeli_Unchecked" IsEnabled="False"/>
                </StackPanel>
     
                <telerik:RadDataPager x:Name="rDataPager" PageSize="8" Margin="800,0,10,0" BorderThickness="0,0,0,0" Source="{Binding Items, ElementName=gridOrdini}" HorizontalAlignment="Right" ></telerik:RadDataPager>
                <telerik:RadGridView x:Name="gridOrdini" SelectionUnit="FullRow"  AutoGenerateColumns="False" CanUserInsertRows="False" CanUserDeleteRows="False" RowIndicatorVisibility="Collapsed"
                ShowGroupPanel="False" IsReadOnly="False" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" SelectionMode="Single" CanUserReorderColumns="False"
                FontFamily="Source Sans Pro Semibold" FontSize="16" GridLinesVisibility="Horizontal" IsFilteringAllowed="False" RowHeight="45" RowStyleSelector="{StaticResource stadiumCapacityStyle}" >
                   
                <telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn x:Name="Vettore1" UniqueName="Vettore1" Header="Vettore" IsReadOnly="True" IsVisible="False" Width="60" DataMemberBinding="{Binding Vettore1}"/>
                        <telerik:GridViewDataColumn x:Name="idOrdCli" Header="idOrdCli" IsReadOnly="True" IsVisible="False" DataMemberBinding="{Binding idOrdCli}" Width="100"/>
                        <telerik:GridViewDataColumn x:Name="Position" Header="Position" IsReadOnly="True" IsVisible="False" DataMemberBinding="{Binding Position}" Width="100"/>
                        <telerik:GridViewDataColumn x:Name="Articolo" Header="Articolo" IsReadOnly="True" DataMemberBinding="{Binding Articolo}" Width="100"/>
                        <telerik:GridViewDataColumn x:Name="Descri" Header="Descrizione" IsReadOnly="True" DataMemberBinding="{Binding Descri}" Width="*"/>
                        <telerik:GridViewDataColumn x:Name="Quantita" Header="Quantità" IsReadOnly="True" DataMemberBinding="{Binding Quantita}" Width="80"/>
                        <telerik:GridViewDataColumn x:Name="QtaPrelevata" Header="Prelevata" IsReadOnly="True" DataMemberBinding="{Binding QtaPrelevata}" Width="80"/>
                        <telerik:GridViewDataColumn x:Name="Reparto" Header="Reparto" IsReadOnly="True" DataMemberBinding="{Binding Reparto}" Width="80"/>
                        <telerik:GridViewDataColumn x:Name="UnMis" Header="UnMis" IsReadOnly="True" DataMemberBinding="{Binding UnMis}" Width="60"/>
                        <telerik:GridViewDataColumn x:Name="Cella" Header="Cella" IsReadOnly="True" DataMemberBinding="{Binding Cella}" Width="60"/>
                        <telerik:GridViewDataColumn x:Name="GruppoCella" Header="GruppoCella" IsReadOnly="True" DataMemberBinding="{Binding GruppoCella}" Width="80"/>
                        <telerik:GridViewDataColumn x:Name="CatMerc" Header="CatMerc" IsReadOnly="True" DataMemberBinding="{Binding CatMerc}" Width="80"/>
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>
            </StackPanel>
        </telerik:RadBusyIndicator>
    </UserControl>

    and my StadiumCapacityStyle.vb class is this:

    Imports System.Data
     
    Public Class StadiumCapacityStyle
        Inherits StyleSelector
        Public Overrides Function SelectStyle(item As Object, container As DependencyObject) As Style
     
            Dim riga As DataRow = item
            If IIf(IsDBNull(riga(4)), 0, riga(4)) > riga(3) Then
                Return BigStadiumStyle
            Else
                Return SmallStadiumStyle
            End If
     
            Return Nothing
        End Function
        Public Property BigStadiumStyle() As Style
            Get
                Return m_BigStadiumStyle
            End Get
            Set
                m_BigStadiumStyle = Value
            End Set
        End Property
        Private m_BigStadiumStyle As Style
        Public Property SmallStadiumStyle() As Style
            Get
                Return m_SmallStadiumStyle
            End Get
            Set
                m_SmallStadiumStyle = Value
            End Set
        End Property
        Private m_SmallStadiumStyle As Style
    End Class

     

    But now I have no row displayed in my radgridview (see attached image).

    What am I doing wrong? 

    Thank you 

     

     

     

     

  5. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    277 posts

    Posted 02 Aug Link to this post

    Hello,

    Can you confirm what type of binaries do you use for your application? If you are using the NoXaml binaries, you have to base the style on the default one for the element when making such changes. Please, try the following:

    <local:StadiumCapacityStyle.BigStadiumStyle>
                    <Style TargetType="telerik:GridViewRow" BasedOn="{StaticResource GridViewRowStyle}">
                        <Setter Property="Background" Value="Red"/>
                    </Style>
                </local:StadiumCapacityStyle.BigStadiumStyle>
                <local:StadiumCapacityStyle.SmallStadiumStyle>
                    <Style TargetType="telerik:GridViewRow" BasedOn="{StaticResource GridViewRowStyle}">
                        <Setter Property="Background" Value="Yellow" />
                    </Style>
                </local:StadiumCapacityStyle.SmallStadiumStyle>


    Regards,
    Stefan Nenchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Start
    Start avatar
    12 posts
    Member since:
    Feb 2015

    Posted 24 Aug in reply to Stefan Nenchev Link to this post

    Yes yes yes! Thank you very much! With that "BasedOn" everything works now!

Back to Top
UI for WPF is Visual Studio 2017 Ready