Doing greater than/less than comparisons on textblocks?

2 posts, 0 answers
  1. Ahmed
    Ahmed avatar
    3 posts
    Member since:
    Dec 2011

    Posted 20 Jan 2012 Link to this post

    My situation is as follows:

    I have a grid of text blocks which are supposed to be ordered in alphabetical order, like say:


    and I'd like to write a test case to verify this.

    The issues I have are two fold:

    How do I do a comparison check between rows? As in check if row 2 is greater than row 1, then check if row 3 is greater than row 2, so on and so forth. I know I can do tests for the values in a single row but not sure how I'm supposed to tell the program to keep going down new rows programatically.

    My other somewhat more pressing problem is that I've found text blocks do not have greater than/less than comparisons. A number based property such as 'ActualHeight' does have such comparisons and it seems strange text blocks do not considering C# does have gerater than and less than operations you can carry out on strings (and this is how the grid we're using orders data).

    So any ideas on what I should do to achieve this? I'm using silverlight.    
  2. Anthony
    Anthony avatar
    19 posts

    Posted 20 Jan 2012 Link to this post

    Hello Ahmed,

    1. This can be accomplished in a coded step. See the following example against this Microsoft Silverlight demo site. After navigating there, I click "DataGrid" in the left-hand menu, then I click the "FirstName" header cell to alphabetize that column. Here is the subsequent coded step:

    SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
    DataGrid grid = app.Find.ByAutomationId<DataGrid>("dataGrid");
    int r = grid.Rows.Count;
    List<string> list = new List<string>();
    for (int i = 0; i < r; i++)
        DataGridRow row = grid.Rows[i];
        DataGridCell cell = row.Cells[2];   
    for (int j = 0; j < list.Count; j++)
        if (j+1 == list.Count)
            Assert.IsTrue(list[j+1].CompareTo(list[j]) >= 0);
    2. Ensure you target the .Text property of the TextBlock to access the CompareTo method:

    SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
    TextBlock tb = app.Find.ById<TextBlock>("test");
    string a = "alpha";

    All the best,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top