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

Scrolling with virtualization

6 Answers 253 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gerard Kerbourch
Top achievements
Rank 1
Gerard Kerbourch asked on 28 May 2010, 08:38 AM
Hello!

We have an application, and a part of this allows us to display parts of our DataBase (it can be a great one) in a RadGridView which has Virtualization turned on (we need it).
We applied a style on the dates displayed ("01/01/1900", default date, must be in LightGray color), and when we scroll in a vertical way, the style is not apply like it should (some dates are in LightGray, even if they're not default date, vice versa).
And here is the mysterious one: when we move the horizontal ScrollBar, this problem not happen, and the style is perfectly apply. It's even repairing the problem of the vertical scrolling.

Is there a solution for our first problem?

And isn't the second point a bug?

Thank you!

6 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 28 May 2010, 11:54 AM
Hello Gerard Kerbourch,

May I see how do you apply the style. In order to avoid such thing happening the routine approach here would be to apply the style in the RowLoaded event via Binding.

When virtualization is turned on , cells are being reused/recycled which may be the reason for the observed strange behavior. The approach described above should solve the issue.
In case you have furhter troubles, just paste me your code and I will try to find a solution for you.

Best wishes,
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
Gerard Kerbourch
Top achievements
Rank 1
answered on 31 May 2010, 09:32 AM
Thank you for the answer!

The problem is partly solved, because now, it's applying the style when we scroll with the horizontal bar. But if we use the vertical one, then the horizontal, it's applying the style on every columns, even if they're not concerned by the style...

When the Virtualization is disabled, the problem disappear but the scrolling is really tedious...

I'd like to send you our code, but our application is really big, and build in a very dynamic way so I'll prefer find a solution without having to send the code, because it will be necessarily a really big part of code...If you see what I mean...

0
Gerard Kerbourch
Top achievements
Rank 1
answered on 02 Jun 2010, 08:02 AM
This is when we use RowLoaded and StyleSelector. When we just use RowLoaded, we have to scroll vertically to see the style applying.
0
Pavel Pavlov
Telerik team
answered on 03 Jun 2010, 12:36 PM
Hi Gerard Kerbourch,

Speaking of style selectors- I have prepared a small app with conditional formatting with style selector.
Please find it attached . I have tested it and it seems to behave correctly .
It does not utilize the RowLoaded events , which simplifies things.

Can you use this approach in your application.

Best wishes,
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
Gerard Kerbourch
Top achievements
Rank 1
answered on 07 Jun 2010, 09:36 AM

Thank you for answering,

We already use this approach, but the problem seems to be with the
But when we use StyleSelector, the horizontal scrolling works well, but when we use the vertical one, on the columns that contains dates, the style is applying in a wrong way, and it's reflected on the others columns.

Here is, finally, the interesting parts of our code:

<UserControl xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"  x:Class="_3GRC.Silverlight.Controls.Common._3GGrille" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" 
    xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView" 
    Width="Auto" Height="Auto" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"   
             xmlns:local="clr-namespace:_3GRC.Silverlight.Controls.Common" 
    > 
 
    <UserControl.Resources> 
        <DataTemplate x:Key="RuntimeContentTemplate">  
            <ContentControl Loaded="ContentControl_Loaded"/>  
        </DataTemplate> 
    </UserControl.Resources> 
 
    <Grid x:Name="LayoutRoot" Background="White" > 
        <Grid.Resources> 
            <local:MyStyleSelector x:Key="styleSelector" /> 
        </Grid.Resources> 
 
        <Grid.RowDefinitions> 
            <RowDefinition Height="*" /> 
            <RowDefinition Height="24" /> 
        </Grid.RowDefinitions> 
 
        <telerik:RadGridView Name="grd_Main" Grid.Row="0"   
            VerticalAlignment="Stretch" HorizontalAlignment="Stretch"   
            ItemsSource="{Binding}" AutoGenerateColumns="False"   
            ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollMode="RealTime"   
            CellValidating="grd_Main_CellValidating" > 
        </telerik:RadGridView> 
 
 
        <telerik:RadDataPager x:Name="radDataPager" Grid.Row="1" 
            PageIndexChanged="radDataPager_PageIndexChanged" 
            PageSize="1" Source="{Binding}" DisplayMode="First, Last, Next, Previous, Text" 
            IsTotalItemCountFixed="True">  
 
        </telerik:RadDataPager> 
    </Grid> 
 
</UserControl> 
 

Our StyleSelector:
Imports Telerik.Windows.Controls  
Imports Telerik.Windows.Controls.GridView  
Imports System.Windows.Markup  
 
 
''' <summary>  
'''   
''' </summary>  
''' <remarks></remarks>  
Public Class MyStyleSelector  
    Inherits StyleSelector  
 
    Public Overloads Overrides Function SelectStyle(ByVal item As ObjectByVal container As DependencyObject) As Style  
 
        Dim Style = New Style(GetType(GridViewCell))  
 
        Dim myCell = DirectCast(container, GridViewCell)  
 
        Style.TargetType = GetType(GridViewCell)  
 
        If myCell.Value.Equals("01/01/1900"Then 
            Style.Setters.Add(New Setter(GridViewCell.ForegroundProperty, New SolidColorBrush(Colors.LightGray)))  
        Else 
            Style.Setters.Add(New Setter(GridViewCell.ForegroundProperty, New SolidColorBrush(Colors.Black)))  
        End If 
 
        Return (Style)  
    End Function 
    Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T  
        target = value  
        Return (value)  
    End Function 
End Class 
 
 
And here, the way we are filling the RadGridView grd_Main
    Public Sub SetDataSource(ByVal data As String)  
 
        Try 
 
            table = New DataTable  
 
            Dim cultureInfo As New CultureInfo("fr-FR")  
 
            For Each item In lst_columns  
 
                Dim ocol As DataColumn = New DataColumn  
 
                With ocol  
 
                    .ColumnName = item.Value.Tag  
 
                    Select Case item.Value.Type  
                        Case Is = "adDBTimeStamp" 
                            .DataType = System.Type.GetType("System.DateTime")  
                            If item.Value.Format.Equals(""Then 
                                '.DataType = System.Type.GetType("System.DateTime")  
                                DirectCast(grd_Main.Columns(item.Value.Tag), GridViewDataColumn).DataFormatString = "{0:dd/MM/yyyy}" 
                            Else 
                                DirectCast(grd_Main.Columns(item.Value.Tag), GridViewDataColumn).DataFormatString = "{0:" + item.Value.Format + "}" 
                            End If 
                            grd_Main.Columns(item.Value.Tag).CellStyleSelector = Me.LayoutRoot.Resources("styleSelector")  
 
                        Case Is = "adBoolean" 
                            .DataType = System.Type.GetType("System.Boolean")  
 
                        Case Else 
                            .DataType = System.Type.GetType("System.String")  
 
                    End Select 
 
                End With 
 
                table.Columns.Add(ocol)  
 
            Next 
 
            Dim doc = XDocument.Parse(data)  
            Dim lng_cptRows As Long = 0  
 
            ' on parse le document XML  
            For Each root As XElement In doc.Descendants("Table").Descendants("Table")  
 
                Dim row = New DataRow  
                For Each elem As XElement In root.Descendants  
                    For Each item In lst_columns  
                        If item.Value.Tag.Equals(elem.Name.ToString.Replace(".""_").Replace(" ""_")) Then 
                            Select Case item.Value.Type  
 
                                Case "adDBTimeStamp" 
                                    If elem.Value IsNot Nothing Then 
                                        Dim str_DateTemp As String = "" 
                                        Dim dt As DateTime = New DateTime()  
                                        'DateTime.TryParse(elem.Value.ToString(cultureInfo), cultureInfo, DateTimeStyles.None, dt).ToString()  
                                        dt = DateTime.ParseExact(elem.Value.ToString, "MM/dd/yyyy", cultureInfo)  
                                        row(item.Value.Tag) = dt  
                                    End If 
                                Case "adBoolean" 
                                    row(item.Value.Tag) = Boolean.Parse(elem.Value)  
 
                                Case Else 
                                    row(item.Value.Tag) = elem.Value.ToString  
 
                            End Select 
                            Exit For 
                        End If 
                    Next 
                Next 
                table.Rows.Add(row)  
                Dim str_test As String = "" 
                Dim color As Color = New Color  
                ' Pour chaque colonne de la datatable  
                For Each col In table.Columns  
                    ' Si la lng_cptRows-ième colonne de la datatable ne contient pas la colonne courante,   
                    If Not table.Rows(lng_cptRows).Keys.Contains(col.ColumnName) Then 
                        ' Si cette colonne est de type DateTime  
                        If col.DataType Is GetType(DateTime) Then 
                            ' On met la valeur "01/01/1900" qui est la date par défaut  
                            table.Rows(lng_cptRows).Item(col.ColumnName) = DateTime.Parse("01/01/1900")  
                        End If 
                    End If 
                Next 
                lng_cptRows = lng_cptRows + 1  
            Next 
 
            grd_Main.ItemsSource = table.ToList()  
 
            ' On passe Ã  False l'a virtualisation de la grille (rafraîchissement des données Ã  chaque scrolling vertical)  
            'grd_Main.EnableColumnVirtualization = False  
 
        Catch ex As Exception  
            Dim err As ChildErrorBox = New ChildErrorBox(2, New Diagnostics.StackFrame(), , ex.Message)  
            err.Show()  
        End Try 
    End Sub 
 

0
Pavel Pavlov
Telerik team
answered on 10 Jun 2010, 11:54 AM
Hi Gerard Kerbourch,

Both our online samples and the project attached have no problems with vertical scrolling . therefore I am unable to reproduce the issue and provide further assistance .

Can you please open a support ticket and attach your project so we can step trough it  and find what is causing the problem

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.
Tags
GridView
Asked by
Gerard Kerbourch
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Gerard Kerbourch
Top achievements
Rank 1
Share this question
or