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

[Solved] Converter in GridView broken in Q3 SP1

4 Answers 116 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.
John M
Top achievements
Rank 1
John M asked on 18 Jan 2010, 05:50 PM
I use a Converter to create a user control for a cell value. In prior releases it worked fine. In the Q3 release, it produces erroneous conversions for rows that are in the scroll regions beyond that which is initially shown.  In other words, the first page of data is OK, but once I scroll I get bogus values for the cell. I set a break point in the Converter and it is returning the correct object.

GridViewDataColumn definition:

<telerik:GridViewDataColumn
DataMemberBinding="{Binding SeverityOrd, Converter={StaticResource SeverityConverter}}"
IsReadOnly="True" IsFilterable="False"  IsGroupable="False" IsSortable="True">

The Converter:

    public class SevConverter : System.Windows.Data.IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return new SevIcon((int)value);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            SevIcon si = (SevIcon)value;
            return si.Sev;
        }
    }




4 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 19 Jan 2010, 10:27 AM
Hi John McGinty,

We tried to reproduce the issues using the sample code that you have provided without any success.  The ticket information indicates that you are using our latest Q3 SP2 release. If you are indeed using our latest release I would like to ask you to send us your application so that we can reproduce the erroneous behavior on our systems and provide you with a solution.


All the best,
Milan
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.
0
John M
Top achievements
Rank 1
answered on 20 Jan 2010, 01:36 AM
Thanks Milan.
Below is an example that exhibits the beahvior. If you instantiate TestGrid and use the vertical scroll bar, you'll see that the column values become unsynchronized (The number in the "Raw" column should math the number in the "Converted column). This code works as exepcted in prior releases.


<
UserControl x:Class="ZWebClientRules.TestGrid" 
    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:local="clr-namespace:ZWebClientRules" 
    Width="400" Height="300"> 
    <Grid x:Name="LayoutRoot" Background="Transparent"> 
 
        <telerik:RadGridView x:Name="grid" Margin="0"  
            BorderThickness="0"  FontSize="12"  Height="auto" Width="auto"  Background="Transparent"                              
            RowDetailsVisibilityMode="VisibleWhenSelected"   
            RowIndicatorVisibility="Visible" MultipleSelect="True" UseAlternateRowStyle="True" ShowGroupPanel="False"  
            ColumnsWidthMode="Fill" AutoGenerateColumns="False"   
            IsReadOnly="True" CanUserReorderColumns="False" CanUserInsertRows="False" CanUserFreezeColumns="False" 
            ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollMode="RealTime" 
            HorizontalAlignment="Left" VerticalAlignment="Top"    
            > 
            <telerik:RadGridView.Resources> 
                <local:TestConverter x:Key="TestConverter"/> 
            </telerik:RadGridView.Resources> 
 
            <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Sev, Converter={StaticResource TestConverter}}" Header=" Converted "  
                                            Width="auto" IsReadOnly="True" IsFilterable="False" IsGroupable="False" IsSortable="True"> 
                </telerik:GridViewDataColumn> 
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Sev}" Header=" Raw "  
                                            Width="auto" IsReadOnly="True" IsFilterable="False" IsGroupable="False" IsSortable="True"> 
                </telerik:GridViewDataColumn> 
            </telerik:RadGridView.Columns> 
 
        </telerik:RadGridView> 
 
    </Grid> 
</UserControl> 
 
 
namespace ZWebClientRules 
{ 
    public partial class TestGrid : UserControl 
    { 
        public TestGrid() 
        { 
            InitializeComponent(); 
 
            Loaded += new RoutedEventHandler(TestGrid_Loaded); 
        } 
 
        void TestGrid_Loaded(object sender, RoutedEventArgs e) 
        { 
            List<TestRow> items = new List<TestRow>(); 
            for (int ii = 0; ii < 100; ii++) 
                items.Add(new TestRow(ii)); 
 
            grid.ItemsSource = items; 
            grid.Rebind(); 
        } 
    } 
 
    public class TestRow 
    { 
        public int Sev { get; private set; } 
        public TestRow(int ii) 
        { 
            Sev = (ii % 4) + 1; 
        } 
    } 
 
 
    public class TestConverter : System.Windows.Data.IValueConverter 
    { 
 
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
        { 
            try 
            { 
                TestIcon ti = new TestIcon((int)value); 
                Debug.Assert(ti.Sev == (int)value); 
                return ti; 
            } 
            catch (Exception) 
            { 
                Debug.Assert(false); 
                throw; 
            } 
 
        } 
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
        { 
            TestIcon ti = (TestIcon)value; 
            return ti.Sev; 
        } 
    } 
 
 
 
<UserControl x:Class="ZWebClientRules.TestIcon" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    Width="auto" Height="auto"> 
    <Grid x:Name="LayoutRoot" Background="Transparent"> 
         
        <!-- in the app, this is a more complex control, but just this simple control exhibits the problem --> 
        <TextBlock x:Name="text" FontSize="12" Foreground="Blue"  /> 
 
    </Grid> 
</UserControl> 
 
namespace ZWebClientRules 
{ 
    public partial class TestIcon : UserControl 
    { 
        public TestIcon() 
        { 
            InitializeComponent(); 
        } 
 
        public int Sev { get; private set; } 
 
        public TestIcon(int sev) 
        { 
            InitializeComponent(); 
 
            Sev = sev; 
            text.Text = String.Format("S{0}", sev); 
        } 
 
    } 
} 
 
0
Milan
Telerik team
answered on 21 Jan 2010, 05:25 PM
Hi John M,

There seems to be a problem with our virtualization mechanism when a converter returns a UserControl. Currently I can offer you a very simple workaround - the idea is to use our simpler column GridViewColumn and a custom CellTemplate:

<telerik:GridViewColumn Header=" Converter " Width="SizeToHeader">
    <telerik:GridViewColumn.CellTemplate>
        <DataTemplate>
            <ContentPresenter Content="{Binding Sev, Converter={StaticResource TestConverter}}"/>
        </DataTemplate>
    </telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>

This version should work as expected. Hope it helps.


Regards,
Milan
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.
0
John M
Top achievements
Rank 1
answered on 21 Jan 2010, 05:54 PM
Great, that works. Thanks!!
Tags
GridView
Asked by
John M
Top achievements
Rank 1
Answers by
Milan
Telerik team
John M
Top achievements
Rank 1
Share this question
or