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

AlternationCount problem ?

1 Answer 56 Views
This is a migrated thread and some comments may be shown as answers.
Marjeta Segrec
Top achievements
Rank 1
Marjeta Segrec asked on 28 Nov 2009, 01:48 PM

I am using RowLoaded event for custom implementation - there is NO problem but problem occure if I set AlternationCount = 2. After that if you scrolling up/down the row.cells are duplicated and also Alternation style is not correct. I am prepared a simple sample where can you see the problem. If AlternationCount = 0 there is NO problem.

Option Strict On 
Imports System.Collections  
Imports System.Collections.Generic  
Imports System.Collections.ObjectModel  
Imports System.Globalization  
Imports System.Linq  
Imports System.Net  
Imports System.ServiceModel  
Imports System.Windows  
Imports System.Windows.Data  
Imports System.Windows.Media  
Imports System.Windows.Resources  
Imports System.Xml.Linq  
Imports Telerik.Windows  
Imports Telerik.Windows.Controls  
Imports Telerik.Windows.Controls.GridView  
Partial Public Class MainPage  
    Inherits UserControl  
    Public Sub New()  
        If System.ComponentModel.DesignerProperties.GetIsInDesignMode(MeThen 
        End If ' System.ComponentModel.DesignerProperties.GetIsInDesignMode(Me)  
        AddHandler Me.Loaded, AddressOf OnMainPageLoaded  
        AddHandler Me.RadGrid.RowLoaded, AddressOf OnRadGridRowLoaded  
        Me.RadGrid.AutoGenerateColumns = False 
    End Sub ' New()  
    Private _DataSource As ObservableCollection(Of SampleData)  
    Private ReadOnly Property DataSource() As ObservableCollection(Of SampleData)  
            Return Me._DataSource  
        End Get 
    End Property ' DataSource()  
    Private Sub LoadData()  
        Me._DataSource = New ObservableCollection(Of SampleData)  
        For a As Integer = 0 To 29  
            Me.DataSource.Add(New SampleData(a + 1, String.Concat("Telerik.Windows.Controls.GridView (2009.3.1127.1030) - ", a + 1)))  
        Next ' a As Integer = 0 To 29  
        Me.RadGrid.ItemsSource = Me.DataSource  
    End Sub ' LoadData()  
    Private Sub OnRadGridRowLoaded( _  
        ByVal sender As ObjectByVal e As Telerik.Windows.Controls.GridView.RowLoadedEventArgs)  
        Debug.WriteLine("OnRadGridRowLoaded - e.Row.Cells.Count = " & e.Row.Cells.Count)  
    End Sub ' OnRadGridRowLoaded(ByVal sender As Object, ByVal e As ...GridView.RowLoadedEventArgs)  
    Private Sub SetGrid()  
        Me.RadGrid.AlternationCount = 2  
        ' sample result :  
        'OnRadGridRowLoaded(-e.Row.Cells.Count = 2)  
        'OnRadGridRowLoaded(-e.Row.Cells.Count = 4)  
        'OnRadGridRowLoaded(-e.Row.Cells.Count = 2)  
        'OnRadGridRowLoaded(-e.Row.Cells.Count = 4)  
        'OnRadGridRowLoaded(-e.Row.Cells.Count = 4)  
        'OnRadGridRowLoaded(-e.Row.Cells.Count = 2)  
        Me.RadGrid.CanUserFreezeColumns = False 
        Me.RadGrid.CanUserReorderColumns = False 
        Me.RadGrid.RowIndicatorVisibility = Windows.Visibility.Collapsed  
    End Sub ' SetGrid()  
    Private Sub OnMainPageLoaded(ByVal sender As ObjectByVal e As System.Windows.RoutedEventArgs)  
    End Sub ' OnMainPageLoaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)  
End Class ' MainPage  
Public Class SampleData  
    Private _ID As Integer = 0  
    Private _Name As String = String.Empty  
    Public Sub New(ByVal [id] As IntegerByVal [name] As String)  
        Me.ID = [id]  
        Me.Name = [name]  
    End Sub ' New(ByVal [id] As Integer, ByVal [name] As String)  
    Public Property ID() As Integer 
            Return Me._ID  
        End Get 
        Set(ByVal value As Integer)  
            Me._ID = value  
        End Set 
    End Property ' ID()  
    Public Property Name() As String 
            Return Me._Name  
        End Get 
        Set(ByVal value As String)  
            Me._Name = value  
        End Set 
    End Property ' Name()  
End Class ' SampleData 
<UserControl x:Class="SilverlightRadGridTest.MainPage" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">  
  <Grid x:Name="LayoutRoot">  
        <Border Margin="10" Padding="4">  
            <radgrid:RadGridView x:Name="RadGrid" AutoGenerateColumns="False" ColumnsWidthMode="Fill">  
                    <radgrid:GridViewDataColumn Header="ID" UniqueName="ID" DataMemberBinding="{Binding ID}" /> 
                    <radgrid:GridViewDataColumn Header="Name" UniqueName="Name" DataMemberBinding="{Binding Name}" /> 

Thanks for your answer.

1 Answer, 1 is accepted

Sort by
Kalin Milanov
Telerik team
answered on 30 Nov 2009, 01:03 PM
Hi Marjeta Segrec,

We are aware of this issue and we are looking at a way of fixing it for the future. For now I can only provide you with the following workaround:

Define styles for the both row and alternate row:
<Style x:Key="GridViewRowStyle" TargetType="radgrid:GridViewRow">
    <Setter Property="Background" Value="White" />
<Style x:Key="GridViewAlternateRowStyle" TargetType="radgrid:GridViewRow">
    <Setter Property="Background" Value="Gray" />

then apply it to the RadGridView as follows:
<radgrid:RadGridView x:Name="RadGrid" AutoGenerateColumns="False" ColumnsWidthMode="Fill" RowStyle="{StaticResource GridViewRowStyle}" AlternateRowStyle="{StaticResource GridViewAlternateRowStyle}">   
      <radgrid:GridViewDataColumn Header="ID" UniqueName="ID" DataMemberBinding="{Binding ID}" />  
      <radgrid:GridViewDataColumn Header="Name" UniqueName="Name" DataMemberBinding="{Binding Name}" />  

This should force the application of the background of the row when scrolling and will bypass the issue you are having.

Sincerely yours,
Kalin Milanov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Asked by
Marjeta Segrec
Top achievements
Rank 1
Answers by
Kalin Milanov
Telerik team
Share this question