Ranorex

How to Select a Cell with a Value

 
Post new topic   Reply to topic    Ranorex Forum Index -> RanorexNet
View previous topic :: View next topic  
Author Message
kimballae



Joined: 08 May 2007
Posts: 1

PostPosted: Tue May 08, 2007 11:07 pm    Post subject: How to Select a Cell with a Value
How do you select a child element that is a Cell that has a specific value? When I use Ranorex Spy the current value is displayed. I assume there is some way to select the specific cell.

BTW - This is a really cool product, good job.
Back to top
View user's profile Send private message
andypicch



Joined: 09 May 2007
Posts: 1

PostPosted: Wed May 09, 2007 5:10 pm    Post subject: Working with grids
Yeah, I think it would be great to see some sample code on how to handle grids in general. How to retrieve and post data to specific cells and how to search cells, rows and columns for specific data... if any or all of that is possible.
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 05 Jul 2006
Posts: 351

PostPosted: Wed May 09, 2007 9:39 pm    Post subject:
The following sample demonstrates how to read and write cell elements of a grid view.
This code works with the Microsoft DataGridView Control sample.
You can download the sample application from:

http://msdn2.microsoft.com/en-us/library/1x64c23x.aspx

Code: click into code to enlarge
class Program
{
    static public void DumpElementTree(Element element, int level)
   {
      level++;
      int childCount = element.GetChildCount;

        for (int index = 0; index < childCount && index < 10; index++)
        {
         Element child = element.GetChild(index);
         if( child == null )
            continue;
         
         string space = new string(' ', 2*level);
         Console.WriteLine("{0}Role={1} Name={2} Value={3}",
                space, child.Role.ToString(), child.Name, child.Value);
         DumpElementTree(child,level);
      }
   }

   /// <summary>
   /// The main entry point for the application.
   /// </summary>
   [STAThread]
   static int Main(string[] args)
    {
        int ret;
        Application.SleepTime = 10;

        //-----------------------------------------
        // F O R M   search and test
        //-----------------------------------------
        Form form = Application.FindFormTitle("Customer Order Viewer");
        if (form == null)
        {
            Console.WriteLine("Cannot find application \"Customer Order Viewer\"");
            return 1;
        }

        Console.WriteLine("Application found");
        form.Activate();

        //-----------------------------------------
        // Find   G R I D   V I E W
        //-----------------------------------------
        Control dataGridView1 = form.FindControlName("dataGridView1");
        if (dataGridView1 == null)
        {
            Console.WriteLine("ERROR: dataGridView1 not found ");
            return 1;
        }

        // Dump out some elements
        DumpElementTree(dataGridView1.Element, 0);

        // Find the element by name
        Element contactRow7 = dataGridView1.Element.FindChild(Role.Cell, "Contact Name Row 7");
        if (contactRow7 != null)
            contactRow7.Value = "Ranorex";

        // Find cell by value
        Element pedro = dataGridView1.Element.FindChildValue("Pedro Afonso",SearchMatchMode.MatchExact);
        if ( pedro != null )
        {
            Console.WriteLine("  Name={0} Value={1}", pedro.Name, pedro.Value);
            Mouse.MoveToElement(pedro);
        }

        Console.WriteLine("\nTEST PASSED\n");
        return 0;

    }
}


You cannot search a cell by value in V1.1.0, but you will be able to search an element by value in the next version.

Code: click into code to enlarge
dataGridView1.Element.FindChildValue("Pedro Afonso",SearchMatchMode.MatchExact);

You will be able to search the sub-tree of the element and return the children that match the specified value and search mode. You can also use regular expression.

Please contact us if you want to test the function Element.FindChildValue.
We can send you a trial of the next version.

Jenö
Ranorex Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Ranorex Forum Index -> RanorexNet All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum