Looping through specific Column : How To …

Looping through specific Column

Best practices, code snippets for common functionality, examples, and guidelines.

Looping through specific Column

Postby riccardo » Mon May 03, 2010 11:15 pm

The following code goes through the whole table, I would like to go only through the cells where the Header has a specific Value. Any Idea how this can be done?

Code: Select all
         foreach (Row rows in repo.Grid.Grid.Rows) {
            foreach(Cell c_cell in rows.Cells)
            {
               Report.Info("Cell "+c_cell.Text);
            }
         }
riccardo
 
Posts: 30
Joined: Wed Apr 28, 2010 11:37 pm

Re: Looping through specific Column

Postby Support Team » Tue May 04, 2010 12:59 pm

Hi!

You can use something similar like the following method to get only cells of specific header:
public static void getCellOfSpecificHeader(string strHeaderName)
{
    IList<Ranorex.Cell> myCellList = repo.Form.yourTable.Find<Ranorex.Cell>(".//cell[@accessiblename~'" + strHeaderName + "']");
                    
    foreach(Cell cell in myCellList )
    {
        if(!cell.IsHeader)
            Report.Info("Cell " + cell.Text);                
    }     
}


Regards,
Peter
Ranorex Support Team
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Looping through specific Column

Postby riccardo » Tue May 04, 2010 2:03 pm

Probably my description was not quite clear... sorry about that

So the goal I need to reach is to get all the cell values below the header column where the Header Column Value is "XYZ".
riccardo
 
Posts: 30
Joined: Wed Apr 28, 2010 11:37 pm

Re: Looping through specific Column

Postby Support Team » Wed May 05, 2010 9:30 am

Hi!

This method is exactly what you need. The parameter
string strHeaderName
of the Method is the Headername of your cell. In your example this would be "XYZ".
Call the method in main function like:
getCellOfSpecificHeader("XYZ")

I'm sure this will work for .Net Datagrids.

Regards,
Peter
Ranorex Support Team
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria

Re: Looping through specific Column

Postby riccardo » Wed May 05, 2010 10:42 am

Sorry Peter, my mistake...

Thank you very much, your solution did the Job!
riccardo
 
Posts: 30
Joined: Wed Apr 28, 2010 11:37 pm


Return to How To …

Who is online

Users browsing this forum: No registered users and 0 guests