Completed
Last Updated: 14 Dec 2015 11:59 by ADMIN
ADMIN
Cody
Created on: 14 Aug 2014 22:03
Type: Feature Request
0
Improve RadGridView Scrolling code sample
From ticket 848774

Documentation bug regarding getting information from RadGridViewCell. Basically the example work only partially in probably very few cases (yes I do know it is for Silverlight and I do use WPF but still I suppose it will have same problems with Silverlight also) Here are the problems with it: (http://docs.telerik.com/teststudio/user-guide/code-samples/silverlight/radgridview/scrolling.aspx )
Won’t work if viewPortHeight is ‘0’ (viewPortHeight = (int)VirtualizingPanel.GetProperty(new AutomationProperty("ViewportHeight", typeof(int)));) because you enter endless loop. The app that I can have sometimes lots of tables that will trigger such behavior. But this is the smaller problem
Bigger problem is that sometimes the rows will be traversed actually twice. This will happen if the for instance if extent height is 120% of the viewPortHeight. The first time you will go through the first ‘n’ rows correctly, but then when you scroll you will have 80% old and just 20% new rows. The only way to avoid this is ONLY if the table contains unique row. If not then there is no other way to filter out which rows you have already passed and which not. One way to solve this is using Dictionary (see below code)
The 3rd problem will reveal itself if you do not refresh the grid. When you scrolling. That could be noticed if your initial state has been at the bootom of table at the last page. That is why you need the line in red
The fourth problem would be actually the presence of horizontal scroll, that would add new dimension to the fun J, But for that I will not write code  … yet, though it would be similar the one below
            Dictionary<string, int> rowsHash = new Dictionary<string, int>();
            // Make sure it is scrolled to the very top
            // Walk through the entire grid verifying the data
            vPanel.InvokeMethod("SetVerticalOffset", 0);
            int rowNum = 0;
            while (verticalOffset < extentHeight)
            {
                Grid.Refresh()
                foreach (GridViewRow r in grid.Rows)
                {
                    string rowId = r.Cells[2].Text;
                    if (!rowsHash.Keys.Contains(rowId))
                    {
                        rowsHash.Add(rowId, rowNum++);
                        Console.WriteLine(r.Cells[0].Text + ", " + r.Cells[1].Text + ", " + r.Cells[2].Text + ", " + r.Cells[3].Text + ", " + r.Cells[4].Text + ", " + r.Cells[5].Text + ", " + r.Cells[6].Text);
                    }
                }
                // Scroll down one page
                verticalOffset += viewPortHeight;
                vPanel.InvokeMethod("SetVerticalOffset", verticalOffset);
            }
0 comments