RadGridView.Rows.Count - invalid value

7 posts, 0 answers
  1. Andrei
    Andrei avatar
    12 posts
    Member since:
    Mar 2012

    Posted 14 Jan 2013 Link to this post

    Hello Telerik Team,
    I create a test method:
    [Timeout(900000), TestMethod]
            public void CheckRadGridViewRowsCountTest()
            {
                //Manager.LaunchNewBrowser();
                Manager.LaunchNewBrowser(BrowserType.InternetExplorer, true);
     
                ActiveBrowser.AutoWaitUntilReady = true;
                ActiveBrowser.Window.SetActive();
                ActiveBrowser.Window.SetFocus();
                ActiveBrowser.Window.Maximize();
     
                ActiveBrowser.NavigateTo(@"http://demos.telerik.com/silverlight/#GridView/Sorting");
     
                // Get an instance of the running Silverlight Application.
                app = ActiveBrowser.SilverlightApps()[0];
     
                ActiveBrowser.RefreshDomTree();
                // Get an instance of the running Silverlight Application.
                app = ActiveBrowser.SilverlightApps()[0];
                app.VisualTree.Find.Strategy = FindStrategy.AlwaysWaitForElementsVisible;
                app.VisualTree.Find.WaitOnElementsTimeout = timeout;
     
                RadGridView radGridView1 = app.VisualTree.Find.ByAutomationId<RadGridView>("RadGridView1");
                var rowsCount = radGridView1.Rows.Count;
            }

    When .I start this test, the value of "rowsCount" is 19, but really in radGridView1 we have > 50 rows, so why is this difference?

    Thank you in advance!
  2. Stanislav
    Stanislav avatar
    1 posts
    Member since:
    May 2012

    Posted 14 Jan 2013 Link to this post

    Hello Andrei,

    How many rows are displayed in the RadGridView? Because it looks like it returns the number of rendered and displayed rows. Try to execute .RefreshVisualTree() after you identify the control.

    Kind Regards,
    Stanislav Hordiyenko
  3. Andrei
    Andrei avatar
    12 posts
    Member since:
    Mar 2012

    Posted 15 Jan 2013 Link to this post

    RadGridView radGridView1 = app.VisualTree.Find.ByAutomationId<RadGridView>("RadGridView1");
                app.RefreshVisualTrees();
                radGridView1.Refresh();
                var rowsCount = radGridView1.Rows.Count;
     - no changes.

    "Because it looks like it returns the number of rendered and displayed rows" - ok, but how to identify total number of rows in this radGridView? 
  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 15 Jan 2013 Link to this post

    Hello Andrei,

    The reason you are getting only the visible rows is because of the virtualization. This is a limitation of the Visual Tree contained in the Silverlight engine. Silverlight puts into the Visual Tree only the UI components necessary to render the page on the screen.

    The easiest way to get the total rows count is by dividing the total height of the grid, visible plus non-visible by the height of the row.

    Here is the code:

    FrameworkElement virtualizingPanel = app.Find.ByType("GridViewVirtualizingPanel");
    int extentHeight; // The total height of the grid, visible plus non-visible
    int rowHeight;
    // Detect the extent height and the row height
    extentHeight = (int)virtualizingPanel.GetProperty(new AutomationProperty("ExtentHeight", typeof(int)));

    rowHeight = (int)radGridView1.GetProperty(new AutomationProperty("RowHeight", typeof(int)));
       
    int totalPageRows = 0;   
    totalPageRows = (extentHeight/rowHeight);

    Please check out these articles:

    - RadGridView Total Rows Count

    - RadGridView Scrolling (coded solution)

    - RadGridView Scrolling (non coded)

    Let me know if you need additional help.
    Regards,
    Boyan Boev
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  5. Andrei
    Andrei avatar
    12 posts
    Member since:
    Mar 2012

    Posted 17 Jan 2013 Link to this post

    This works, thank you...

    But now another problem: in this example (http://demos.telerik.com/silverlight/#GridView/Sorting) how to copy ALL [Company Name] in a List<string>()

    I try to do this: 
    Manager.LaunchNewBrowser(BrowserType.InternetExplorer, true);
     
                ActiveBrowser.AutoWaitUntilReady = true;
                ActiveBrowser.Window.SetActive();
                ActiveBrowser.Window.SetFocus();
                ActiveBrowser.Window.Maximize();
     
                ActiveBrowser.NavigateTo(@"http://demos.telerik.com/silverlight/#GridView/Sorting");
     
                // Get an instance of the running Silverlight Application.
                app = ActiveBrowser.SilverlightApps()[0];
     
                ActiveBrowser.RefreshDomTree();
                // Get an instance of the running Silverlight Application.
                app = ActiveBrowser.SilverlightApps()[0];
                app.VisualTree.Find.Strategy = FindStrategy.AlwaysWaitForElementsVisible;
                app.VisualTree.Find.WaitOnElementsTimeout = timeout;
     
                ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                RadGridView radGridView1 = app.VisualTree.Find.ByAutomationId<RadGridView>("RadGridView1");
                FrameworkElement virtualizingPanel = app.Find.ByType("GridViewVirtualizingPanel");
                int radGridViewRowsCount = (int)virtualizingPanel.GetProperty(new AutomationProperty("ExtentHeight", typeof(int))) / (int)radGridView1.GetProperty(new AutomationProperty("RowHeight", typeof(int)));
     
                List<string> cellsValues = new List<string>();
     
                //select first row
                radGridView1.Rows[0].User.Click();
     
                //add visible rows to list               
                for (int index = 0; index < radGridView1.Rows.Count; index++)
                {
                    //System.Diagnostics.Debug.WriteLine("before: " + radGridView.Rows[index].Cells[columnIndex].Value.ToString());
                    cellsValues.Add(radGridView1.Rows[index].Cells[1].Value != null ? radGridView1.Rows[index].Cells[1].Value.ToString() : "");
                    radGridView1.User.KeyPress(System.Windows.Forms.Keys.Down, 500);
                }
     
                int virtualizingRowIndex = 0;
     
                for (int index = radGridView1.Rows.Count; index < radGridViewRowsCount; index++)
                {
                    cellsValues.Add(radGridView1.Rows[virtualizingRowIndex].Cells[1].Value != null ? radGridView1.Rows[virtualizingRowIndex].Cells[1].Value.ToString() : "");
                    radGridView1.User.KeyPress(System.Windows.Forms.Keys.Down, 500);
                    virtualizingRowIndex++;
     
                    if (virtualizingRowIndex >= radGridView1.Rows.Count)
                    {
                        virtualizingRowIndex = 0;
                    }
                }

    but the result not correspond with the reality, what I do wrong ?
  6. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 22 Jan 2013 Link to this post

    Hi Andrei,

    Unfortunately this is a virtualization problem. You can't walk through the entire grid by its index. It is constantly changing. 

    To achieve this you need to implement your own logic for the indexing (e.g. some ID column) then base your logic for walking through the grid on this column for example.

    Hope this helps.

    Greetings,
    Boyan Boev
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  7. Andrei
    Andrei avatar
    12 posts
    Member since:
    Mar 2012

    Posted 22 Jan 2013 Link to this post

    Ok, thank you. I'll try later to find some workarounds.
Back to Top