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

Issue with scrollintoview

8 Answers 119 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 28 Jan 2010, 08:56 AM
Hi,

telerik: 2009.3.1322.35
.net 4.0 beta 2

When I follow the steps below I get an error:
1. Set a filter on gridviewdatacolumn
2. Filtered items set contains a certain dataitem
3. Change this dataitem such that it no longer belongs to filtered items
4.  After the change I scroll into view:
GridView.SelectedItem = _dataItem 
                If GridView.SelectedItem IsNot Nothing Then 
                    GridView.ScrollIntoView(GridView.SelectedItem) 
                End If 

Now I get the following error:



   at Telerik.Windows.Controls.GridView.GridViewVirtualizingPanel.BringIndexIntoView(Int32 index) in c:\Builds\WPF_Scrum\GridView_WPF_2009_Q3_SP1\Sources\Development\Controls\GridView\GridView\GridView\Virtualization\GridViewVirtualizingPanel.BringIntoView.cs:line 29
   at Telerik.Windows.Controls.GridView.GridViewDataControl.ScrollIntoViewRecursive(FrameworkElement element, Stack`1 itemStack, Action`1 scrollFinishedCallback) in c:\Builds\WPF_Scrum\GridView_WPF_2009_Q3_SP1\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Scrolling.cs:line 252
   at Telerik.Windows.Controls.GridView.GridViewDataControl.ScrollRowIntoViewInternal(Object dataItem, Action`1 scrollFinishedCallback) in c:\Builds\WPF_Scrum\GridView_WPF_2009_Q3_SP1\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Scrolling.cs:line 191
   at Telerik.Windows.Controls.GridView.GridViewDataControl.<>c__DisplayClass69.<ScrollIntoViewAsync>b__68() in c:\Builds\WPF_Scrum\GridView_WPF_2009_Q3_SP1\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Scrolling.cs:line 94
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)


8 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 02 Feb 2010, 10:57 AM
Hello Thomas,

We have tried to reproduce this but we could not get the exception no matter what we tried. Could you please prepare a small dummy sample project and send it to us. Also, specify the exact steps that we need to follow in order to get the exception. Once we reproduce this exception, we will debug it and fix the issue. Thanks in advance. We are looking forward to hearing from you.

Regards,
Ross
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Thomas
Top achievements
Rank 1
answered on 02 Feb 2010, 12:10 PM
Hello,


I tried to reproduce with a small example but I got a different exception. Maybe they are related.
See the code below. Set filter cartype=1 ("Ford"). Change comboboxcolumn to "Mercedes". You get an error. RowEditEnded is not even called in this case.
Thank you for your time.

<Window xmlns:my="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"  x:Class="MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      
    Title="MainWindow"
    <Grid> 
        <my:RadGridView Name="GridView1" AutoGenerateColumns="False"  RowEditEnded="GridView1_RowEditEnded"
            <my:RadGridView.Columns> 
                <my:GridViewDataColumn Header="Owner" UniqueName="Owner"/> 
                <my:GridViewComboBoxColumn Header="Type" UniqueName="CarTypeID" SelectedValueMemberPath="CarTypeID" DisplayMemberPath="Type"/> 
            </my:RadGridView.Columns> 
        </my:RadGridView> 
    </Grid> 
</Window> 
 

Imports System.Collections.ObjectModel 
Imports Telerik.Windows.Controls 
Class MainWindow 
 
    Private cars As New ObservableCollection(Of Car) 
    Private cartypes As New ObservableCollection(Of CarType) 
 
    Private Sub MainWindow_Loaded(ByVal sender As ObjectByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded 
        cartypes.Add(New CarType With {.CarTypeID = 1, .Type = "Ford"}) 
        cartypes.Add(New CarType With {.CarTypeID = 2, .Type = "Mercedes"}) 
 
        cars.Add(New Car With {.Owner = "You", .CarTypeID = 1}) 
        cars.Add(New Car With {.Owner = "Me", .CarTypeID = 2}) 
        GridView1.ItemsSource = cars 
        CType(GridView1.Columns(1), GridViewComboBoxColumn).ItemsSource = cartypes 
    End Sub 
 
    Private Sub GridView1_RowEditEnded(ByVal sender As System.ObjectByVal e As Telerik.Windows.Controls.GridViewRowEditEndedEventArgs) 
        GridView1.SelectedItem = CType(e.Row.DataContext, Car) 
        If GridView1.SelectedItem IsNot Nothing Then 
            GridView1.ScrollIntoView(GridView1.SelectedItem) 
        End If 
    End Sub 
End Class 
 

Public Class Car 
 
    Private _owner As String 
    Private _carTypeID As Integer 
 
    Public Property Owner As String 
        Get 
            Return _owner 
        End Get 
        Set(ByVal value As String
            _owner = value 
        End Set 
    End Property 
 
    Public Property CarTypeID As Integer 
        Get 
            Return _carTypeID 
        End Get 
        Set(ByVal value As Integer
            _carTypeID = value 
        End Set 
    End Property 
 
End Class 
Public Class CarType 
    Private _carTypeID As Integer 
    Private _type As String 
 
    Public Property CarTypeID As Integer 
        Get 
            Return _carTypeID 
        End Get 
        Set(ByVal value As Integer
            _carTypeID = value 
        End Set 
    End Property 
    Public Property Type As String 
        Get 
            Return _type 
        End Get 
        Set(ByVal value As String
            _type = value 
        End Set 
    End Property 
 
End Class 
 
0
Rossen Hristov
Telerik team
answered on 02 Feb 2010, 12:31 PM
Hello Thomas,

I created a sample project with the code that you sent me and I do not get any error.

I am using the Latest Internal Build version. Here is what I see. I have attached my sample project.

What are we doing differently?

Sincerely yours,
Ross
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Thomas
Top achievements
Rank 1
answered on 02 Feb 2010, 12:56 PM
Hi,

Excuse me, I used an older build in the example. But I have made some changes, that do reproduce the same error with the latest build.
Set  filter to 1 again, select the row and push the button.


Imports System.Collections.ObjectModel 
Imports Telerik.Windows.Controls 
Class MainWindow 
 
    Private cars As New ObservableCollection(Of Car) 
    Private cartypes As New ObservableCollection(Of CarType) 
 
    Private Sub MainWindow_Loaded(ByVal sender As ObjectByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded 
        cartypes.Add(New CarType With {.CarTypeID = 1, .Type = "Ford"}) 
        cartypes.Add(New CarType With {.CarTypeID = 2, .Type = "Mercedes"}) 
 
        cars.Add(New Car With {.Owner = "You", .CarTypeID = 1}) 
        cars.Add(New Car With {.Owner = "Me", .CarTypeID = 2}) 
        GridView1.ItemsSource = cars 
        CType(GridView1.Columns(1), GridViewComboBoxColumn).ItemsSource = cartypes 
    End Sub 
 
    Private Sub GridView1_RowEditEnded(ByVal sender As System.ObjectByVal e As Telerik.Windows.Controls.GridViewRowEditEndedEventArgs) 
        
    End Sub 
 
    Private Sub button1_Click(ByVal sender As System.ObjectByVal e As System.Windows.RoutedEventArgs) 
        Dim _car As Car = TryCast(GridView1.SelectedItem, Car) 
        If _car IsNot Nothing Then 
            If _car.CarTypeID = 1 Then 
                _car.CarTypeID = 2 
            Else 
                _car.CarTypeID = 1 
            End If 
        End If 
        GridView1.Rebind() 
        GridView1.SelectedItem = _car 
        If GridView1.SelectedItem IsNot Nothing Then 
            GridView1.ScrollIntoView(GridView1.SelectedItem) 
        End If 
 
    End Sub 
End Class 

<Window xmlns:my="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"  x:Class="MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      
    Title="MainWindow"
    <Grid> 
        <StackPanel> 
            <my:RadGridView Name="GridView1" AutoGenerateColumns="False"  RowEditEnded="GridView1_RowEditEnded"
            <my:RadGridView.Columns> 
                <my:GridViewDataColumn Header="Owner" UniqueName="Owner"/> 
                <my:GridViewComboBoxColumn Header="Type" UniqueName="CarTypeID" SelectedValueMemberPath="CarTypeID" DisplayMemberPath="Type"/> 
            </my:RadGridView.Columns> 
        </my:RadGridView> 
        <Button Name="button1" Click="button1_Click">Change owner</Button> 
            </StackPanel> 
    </Grid> 
</Window> 
 
0
Rossen Hristov
Telerik team
answered on 02 Feb 2010, 01:37 PM
Hello Thomas,

You really got me confused with this one. You apply a filter to make only the Ford visible. Then you take the Ford and make it a Mercedes so that it disappears. Nothing is left in the grid because we now have two Mercedes. You then want to select an item that is not visible. Why do you want to select and scroll an item that has just disappeared because you filtered it out?

I am completely lost. Please, elaborate.

We might place a block of code that checks whether the item passed in as a parameter to the ScrollIntoView method is correct and valid. Still, we would like to know why do you need to pass in an invalid argument to the ScrollIntoView method and how do you expect it behave in such a case.

We are looking forward to hearing from you.

Regards,
Ross
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Thomas
Top achievements
Rank 1
answered on 02 Feb 2010, 02:32 PM
Hi,

I will try to explain.

I have a form where I can fill in my datarecord. I also have a "add" and "update" button.
If I push the add button I will insert the record that I have prepared in the form and after that I like to scroll into view in the gridview to show the user  the newly inserted record.
This can go wrong now if the user has set a filter on the grid.
(There are many ways the user can set a filter or filters on the grid, this makes it difficult to test at forehand if the new record will be part if the filtered gridview, that's why I always like to scrollintoview )

By the way, I like to use the scroll into view for all situations where I have a list with sorted items and an insert/edit possibility. Because otherwise the inserted item can be out of view after roweditended.

I hope this clarifies a little bit.

Best regards,
Thomas.





0
Rossen Hristov
Telerik team
answered on 02 Feb 2010, 03:00 PM
Hello Thomas,

Now, this makes sense. Thank you for elaborating. We will defend against such cases and ScrollIntoView will simply do nothing if there is no such item instead of throwing an exception. Will this be an acceptable solution? In fact, I cannot think of another one.

The fix will be available with out Latest Internal Build due this Friday.

Until then, you can simply do the following:

Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    Dim _car As Car = TryCast(GridView1.SelectedItem, Car)
    If _car IsNot Nothing Then
        If _car.CarTypeID = 1 Then
            _car.CarTypeID = 2
        Else
            _car.CarTypeID = 1
        End If
    End If
 
    GridView1.Rebind()
 
    If GridView1.Items.Contains(_car) Then
        GridView1.SelectedItem = _car
        GridView1.ScrollIntoView(GridView1.SelectedItem)
    End If
 
End Sub

ItemsSource is the original "full" data source, while Items are the active items, i.e. the ones that are currently in the grid. You can build upon this further.

I hope this helps.

Regards,
Ross
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Thomas
Top achievements
Rank 1
answered on 02 Feb 2010, 03:31 PM
Hello Ross,

I'm glad that made sense to you ;)

Your solution is just what I need.
Many thanks,

Thomas.
Tags
GridView
Asked by
Thomas
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Thomas
Top achievements
Rank 1
Share this question
or