When I verified a cell's value in a datagrid with pagination, I failed to get all the pages row count but only the current page.
It seems the 'grid.Rows.Count' just get the current page row count, 5 here.
And I want to get all the 7 pages row count, how can I to realize this? Reminder, the records on the last page,Page 7, may be less than 5.
And the values I verified ('test for comment26') is indeed on the 1st page, even though, it failed.
Attachment the screenshot and my coded step fails below, and hope they help.
Thanks in advance and have a nice weekend.
//Get the data grid.
SilverlightApp app = ActiveBrowser.SilverlightApps();
DataGrid grid = app.Find.ByAutomationId<DataGrid>("RelatedCommentsDataGrid");
int r = grid.Rows.Count;
List<string> list = new List<string>();
//Place the TextBlock content of the comment subject cell from each row into the string list.
for (int i = 0; i < r; i++)
DataGridRow row = grid.Rows[i];
DataGridCell cell = row.Cells;
//Get the created comment subject
object createdComment = GetExtractedValue("CommentSubject");
//Compare the created comment subject to the list and determine if it created successfully.
for (int j = 0; j < list.Count; j++)
if (j+1 == list.Count)
Log.WriteLine(createdComment+"is created successfully");
Log.WriteLine(createdComment+"fails to created" );
8 Answers, 1 is accepted
Thank you for your quick response.
I went through that article before and noticed it's about Radgridview, is that method also applicable to datagrid?
When I applied them to my test case, it failed at this line, and I will attach the detailed error:
// Grab the VirtualizingPanel contained in the RadGridView. This is used to control the viewable portion of the grid.
FrameworkElement VirtualizingPanel = grid.Find.ByType("GridViewVirtualizingPanel");
I have no idea what 'GridViewVirtualizingPanel' mentioned, is it property of radgridview?
If yes, is it also property of datagrid?
Due to the error 'Element Not found!', maybe it's not.
The VirtualizingPanel is a RadGridView child element, which contains the row elements. The provided code sample solution is not applicable for a regular DataGrid.
However, I've managed to create a working sample for you against the MS Silverlight DataGrid. Here's the code:
Sample Test Studio project is attached. Check this video to see how it works and let me know if you need further assistance on this.
the Telerik team
Thank you very much for your detailed reply.
But the get row count method may be not applicable to my application.
// Get the rows count for the current page
totalPageRows = grid.RowElements.Count; '
--- It returns the wrong value for the last page. eg. the last page is 2nd page with 1 records.
"Total overall rows count is: " 10, no matter how many records on the last page.
(The max row count is 5)
How to handle the page with the random rows(not the maximum row count)?
Attached is the 1st & last page view, hope it can help.
I'm sorry to hear it doesn't work in your case. First, try adding the following line after the right after the next button click line:
This should refresh the grid and you should be able to get the correct row count. If it still doesn't work. Please try the following code as work-around:
Hope this helps!
the Telerik team
Sorry for responsing so late as some other on-going project.
And Thank you very much for your detailed answer.
But I'm sorry to say that it still doesn't work.
The rows account returns is still as 'the maximum rows/page * page numbers', no matter how many rows actually exsit on the last page.
Have you tried with this approach? To find each grid every time inside the loop instead of outside, and before using Find try refresh on entire App window just to be sure. The code below works for me in a simular case, but then by using RadGridViews.
Please try Jonas's approach and let us know if it works for you. If you still have problem getting the rows count, the best way for us to troubleshoot this is to provide the means to reproduce the issue locally(either in your app or on a public site). If you feel that information is sensitive, you can file a support ticket, which is confidential unlike this forum thread.
@Jonas. I've updated your Telerik Points for assisting another customer.
the Telerik team