RadiantQ Forum

Product => WPF Gantt Package => Topic started by: ilkka.paloheimo on March 15, 2016, 01:14:56 PM

Title: Fexy gantt scroll postion after reload -problem
Post by: ilkka.paloheimo on March 15, 2016, 01:14:56 PM
Problem with scroll position when reloading data.
I can reproduce the problem with PerformanceSampleHierData project:
Number of rows: 25. Load Gantt.
Scroll down few lines. Reload Gantt.
Scroll position changes after reload.
Regards,
Ilkka Paloheimo
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: ForumAdmin on March 16, 2016, 10:26:17 PM
Ilkka,

This is a known issue we fixed since our last official release. We sent you an updated assembly. Please confirm fix.

Thanks
RQ Support
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: ilkka.paloheimo on March 17, 2016, 11:05:10 AM
Did not fix my problem!
I changed the dll in PreformanceSampleHierData projoct, too. Did not fix the problem there either.
Regards, Ilkka
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: Rajagopal on March 17, 2016, 02:29:28 PM
Ilkka,

We have also tried your steps to reproduce the reported issue but unfortunately we couldn't.
Please take a look at the video clip that we sent to you and help us to reproduce it.


Thanks,
- Raja.
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: ilkka.paloheimo on March 17, 2016, 03:19:43 PM
In the video the view scrolls to top after reload. If you have say 200 or 1000 rows the view stays where it was before reload. Problem exists only if there are less than 30 rows. My purpose is to keep the same lines on the view after reload what I had before reload.
Regards, Ilkka
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: ForumAdmin on March 18, 2016, 01:30:56 PM
Ilkkka,

Ok, so you want to retain the scroll position after the reload? (We thought for some reason that the grid and chart were going out of sync). We will get back to you shortly on this.

Thanks
RQ Support
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: Karthikeyan on March 23, 2016, 01:01:15 PM
Ilkkka,

Here is the way to retain the scroll position after the reload. You have to add some namespaces, those are given below. To use those namespaces you should include the
UIAutomationProvider.dll and UIAutomationTypes.dll assemblies.

NameSpaces :
Code: [Select]
using System.Windows.Automation.Peers;
using System.Windows.Automation.Provider;

Code :
Code: [Select]
........
/// <summary>
/// Getting the scroll percent value of the chart.
/// </summary>
/// <returns></returns>
private double GetVerticalScrollPercent()
{
    AutomationPeer p;

    if (this.fxgantt.UseChartVirtualization)
        p = FrameworkElementAutomationPeer.FromElement(this.fxgantt.GanttChart.VerticalScrollViewerElement) ?? FrameworkElementAutomationPeer.CreatePeerForElement(this.fxgantt.GanttChart.VerticalScrollViewerElement);
    else
        p = FrameworkElementAutomationPeer.FromElement(this.fxgantt.GanttChart.VerticalScrollViewerElement) ?? FrameworkElementAutomationPeer.CreatePeerForElement(this.fxgantt.GanttChart.VerticalScrollViewerElement);

    var chartScrollProvider = p.GetPattern(PatternInterface.Scroll) as IScrollProvider;

    return chartScrollProvider.VerticalScrollPercent;

}

/// <summary>
/// The types of scrolling directions
/// </summary>
private enum ScrollDirection
{
    Up,
    Down,
    Right,
    Left
}

/// <summary>
/// Setting the scroll value to the grid.
/// </summary>
/// <param name="grid"></param>
/// <param name="direction"></param>
/// <param name="vp"></param>
private void SetVerticalScrollPercent(DataGrid grid, ScrollDirection direction, double vp)
{
    // Get the scroll provider of the grid.
    AutomationPeer p1 = FrameworkElementAutomationPeer.FromElement(grid) ?? FrameworkElementAutomationPeer.CreatePeerForElement(grid);
    IScrollProvider scrollProvider = p1.GetPattern(PatternInterface.Scroll) as IScrollProvider;

    // Scroll.
    switch (direction)
    {
        case ScrollDirection.Up:
        case ScrollDirection.Down:
            if (scrollProvider.VerticallyScrollable)
            {
                scrollProvider.SetScrollPercent(System.Windows.Automation.ScrollPatternIdentifiers.NoScroll, vp);
            }

            break;
        case ScrollDirection.Left:
        case ScrollDirection.Right:
            if (scrollProvider.HorizontallyScrollable)
            {
                scrollProvider.SetScrollPercent(vp, System.Windows.Automation.ScrollPatternIdentifiers.NoScroll);
            }

            break;
    }
}

private void LoadGantt_Click(object sender, RoutedEventArgs e)
{
    // Getting the scroll percent value.
    double vp = this.GetVerticalScrollPercent();

    this._ticks = DateTime.Now.Ticks;
    this.fxgantt.ItemsSource = SampleProjectData.GetSampleData((int)this.rowCountUD.Value);
    this.fxgantt.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Loaded, new Action(delegate()
    {
        // Update log right after the UI thread is free.
        long elapsed = TimeComputingUtils.ToUtcKind(DateTime.Now).Ticks - this._ticks;
        this.UpdateLoadLog((int)this.rowCountUD.Value, elapsed);
    }));

    // Setting the scroll percent to the grid.
    DataGrid grid = ((DataGrid)this.fxgantt.FlexyTable.AsControl);
    this.SetVerticalScrollPercent(grid, ScrollDirection.Up, vp);
}
..........


Thanks,
- Karthik.
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: ilkka.paloheimo on April 04, 2016, 08:44:24 AM
Ok. I had to add an async sleep (400 ms) before SetVerticalScrollPercent so that the gantt view has time to update before repositioning. A disturbing detail is that the view blinks up and down when updating data.
Thanks,
-Ilkka
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: Karthikeyan on April 04, 2016, 11:48:04 AM
Ilkka,

 Can you tell us why you had to use the timer? If we understand this issue better we can come up with a better fix.

Thanks,
-Karthikeyan K.
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: ilkka.paloheimo on April 05, 2016, 08:36:07 AM
Before staring repositioning I have to wait until all layout updates are done by gantt control. Otherwise gantt will override my repositioning.
- Ilkka
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: Rajagopal on April 06, 2016, 03:48:53 PM
Ilkka,

We are looking on this, will update you soon.


Thanks,
- Raja.
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: Karthikeyan on April 07, 2016, 12:21:49 PM
Hi Ilkka,
 
We spent some time with the Reference sample we have trying to reset the ItemsSource when the gantt is vertically scrolled and at no point does the gantt "reset" the scroll position that was set using the SetVerticalScrollPosition. Does this happen in some very specific scenario? If so, can you tell us when? And what .NET framework are you working with 4.0 or 4.5?.


Thanks,
- Karthikeyan
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: ilkka.paloheimo on April 18, 2016, 06:56:03 AM
In my software this (vertical scroll position lost) happens only if I have 3 parents and less than about 140 rows. If I have only 1 parent or I have more than 140 rows the software works fine.  I have tested this with several different databases. In PreformanceSampleHierData sample the problem existed if less than 30 rows. I use .NET framework 4.5.

Regards, Ilkka
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: Karthikeyan on April 19, 2016, 01:17:41 PM
Ilkka,
 
We tested our Performance sample with this many number of rows, but didn't see this issue. Could you let us know what we might be missing?. Please find out the video in www.radiantq.com/External/Support/Hotellinx/Ilkka.avi (http://www.radiantq.com/External/Support/Hotellinx/Ilkka.avi)
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: ilkka.paloheimo on April 23, 2016, 12:09:24 PM
I have data expanded when running the sample.
-Ilkka
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: Karthikeyan on April 25, 2016, 12:50:27 PM
Ilkka,

We tested our Performance sample with Expanded rows, but didn't see this issue. Please find out the video in http://www.radiantq.com/External/Support/Hotellinx/Ilkka_Apr25.avi (http://www.radiantq.com/External/Support/Hotellinx/Ilkka_Apr25.avi)


Thanks,
- Karthikeyan K
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: ilkka.paloheimo on June 29, 2017, 01:40:17 PM
I have to come back to this same problem once again.

We have still problems to get scroll bars correctly synchronized when UseChartVirtualization="True"
It do not happen all the time but when it happens it causes a lot of troubles for the software users.
And we have to use Virtualization because of its efficiency.

we tried to correct this as you succeeded earlier.
But as you see SetVerticalScrollPercent fails to set vertical scroll bar.
It is 100 after set ?????




 Here is what we do:

 Private Function GetVerticalScrollPercent() As Double
        Dim p As AutomationPeer

        If ResourceFlexyGantt.UseChartVirtualization Then
            p = If(FrameworkElementAutomationPeer.FromElement(ResourceFlexyGantt.GanttChart.VerticalScrollViewerElement), FrameworkElementAutomationPeer.CreatePeerForElement(ResourceFlexyGantt.GanttChart.VerticalScrollViewerElement))
        Else
            p = If(FrameworkElementAutomationPeer.FromElement(ResourceFlexyGantt.GanttChart.VerticalScrollViewerElement), FrameworkElementAutomationPeer.CreatePeerForElement(ResourceFlexyGantt.GanttChart.VerticalScrollViewerElement))
        End If
        Dim chartScrollProvider = TryCast(p.GetPattern(PatternInterface.Scroll), IScrollProvider)
        Return chartScrollProvider.VerticalScrollPercent
End Function

Private Sub SetVerticalScrollPercent(grid As DataGrid, direction As ScrollDirection, vp As Double)
        ' Get the scroll provider of the grid.
        Dim p1 As AutomationPeer = If(FrameworkElementAutomationPeer.FromElement(grid), FrameworkElementAutomationPeer.CreatePeerForElement(grid))
        Dim scrollProvider As IScrollProvider = TryCast(p1.GetPattern(PatternInterface.Scroll), IScrollProvider)
        ' Scroll.
        Select Case direction
            Case ScrollDirection.Up, ScrollDirection.Down
                If scrollProvider.VerticallyScrollable Then
                    scrollProvider.SetScrollPercent(System.Windows.Automation.ScrollPatternIdentifiers.NoScroll, vp)
                End If
                Exit Select
            Case ScrollDirection.Left, ScrollDirection.Right
                If scrollProvider.HorizontallyScrollable Then
                    scrollProvider.SetScrollPercent(vp, System.Windows.Automation.ScrollPatternIdentifiers.NoScroll)
                End If
                Exit Select
        End Select
End Sub

Private Async Sub FillFlexyGantt() ' get data

     vp = Me.GetVerticalScrollPercent()

   .......
   read data from Sql Server
   ResevationsItemSource = GetReservations(....
   ' ResevationsItemSource = binding collecton
   .......

    ' Check and set the scroll percent to the grid.
          Do While ResourceFlexyGantt.FlexyTable.AsControl.IsEnabled = False
                Await System.Threading.Tasks.Task.Run( _
                Sub()
                    System.Threading.Thread.Sleep(100) ' Give time for view to be updated before resetting scroll bar
                End Sub)
          Loop
            Dim vp2 As Double = GetVerticalScrollPercent()
            If vp2 <> vp Then
                If vp > 0 And ResourceFlexyGantt.FlexyTable.AsControl.IsEnabled = True Then
                    Dim grid As DataGrid = DirectCast(ResourceFlexyGantt.FlexyTable.AsControl, DataGrid)
                    SetVerticalScrollPercent(grid, ScrollDirection.Up, vp)
                End If
            End If

            System.Diagnostics.Debug.WriteLine("Scroll before: " & vp.ToString & " After: " & vp2.ToString)
     ...........
End Sub
 



Scroll before: 53.3333333333333 After: 100
Scroll before: 56.25 After: 100
Scroll before: 56.25 After: 100
Scroll before: 53.3333333333333 After: 100
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: Rajagopal on June 30, 2017, 01:22:17 PM
Hi Ilkka,

We couldn't reproduce the reported issue. We have sent you the reference sample and video to your email. Can you please help us to reproduce the issue in that reference sample?

Thanks
Raja
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: ilkka.paloheimo on July 13, 2017, 07:21:37 AM
Hello,
This problem don't occur regularly. We have several users of this program but only few has the problem. It seems to depend on the number of lines and group (in all cases less than140 lines and 3-4 groups). In these cases SetVerticalScrollPercent fails to set the value properly. We discovered that if we create a background thread where we have a short delay before we do SetVerticalScrollPercent, it works. But not in same thread with any delay.

I hope that the basic error could be fixed because the view jumps up and down. So this is a cosmetic problem left.
Title: Re: Fexy gantt scroll postion after reload -problem
Post by: Rajagopal on July 13, 2017, 02:20:08 PM
Ilkka,

Thanks for sharing your workaround calling SetVerticalScrollPercent in a separate thread. We will keep an eye on this and fix this as soon as we can reproduce this.


Thanks
Raja