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

AlternationCount problem ?

1 Answer 56 Views
GridView
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
Hello.

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()  
        InitializeComponent()  
 
        If System.ComponentModel.DesignerProperties.GetIsInDesignMode(MeThen 
            Return 
        End If ' System.ComponentModel.DesignerProperties.GetIsInDesignMode(Me)  
        '  
        AddHandler Me.Loaded, AddressOf OnMainPageLoaded  
        AddHandler Me.RadGrid.RowLoaded, AddressOf OnRadGridRowLoaded  
        '  
        Me.RadGrid.AutoGenerateColumns = False 
        Me.SetGrid()  
        Me.LoadData()  
    End Sub ' New()  
 
    Private _DataSource As ObservableCollection(Of SampleData)  
    Private ReadOnly Property DataSource() As ObservableCollection(Of SampleData)  
        Get 
            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)  
        'etc...  
 
 
        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)  
        Me.SetGrid()  
    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 
        Get 
            Return Me._ID  
        End Get 
        Set(ByVal value As Integer)  
            Me._ID = value  
        End Set 
    End Property ' ID()  
 
    Public Property Name() As String 
        Get 
            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" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"   
    xmlns:radgrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"   
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"   
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"   
    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:RadGridView.Columns> 
                    <radgrid:GridViewDataColumn Header="ID" UniqueName="ID" DataMemberBinding="{Binding ID}" /> 
                    <radgrid:GridViewDataColumn Header="Name" UniqueName="Name" DataMemberBinding="{Binding Name}" /> 
                </radgrid:RadGridView.Columns> 
            </radgrid:RadGridView> 
        </Border> 
    </Grid> 
</UserControl> 


Thanks for your answer.
Regards

1 Answer, 1 is accepted

Sort by
0
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>
  
<Style x:Key="GridViewAlternateRowStyle" TargetType="radgrid:GridViewRow">
    <Setter Property="Background" Value="Gray" />
</Style>

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

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.
Tags
GridView
Asked by
Marjeta Segrec
Top achievements
Rank 1
Answers by
Kalin Milanov
Telerik team
Share this question
or