Looping through specific Column

Best practices, code snippets for common functionality, examples, and guidelines.
riccardo
Posts: 30
Joined: Wed Apr 28, 2010 10:37 pm

Looping through specific Column

Post by riccardo » Mon May 03, 2010 10: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);
				}
			}

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Looping through specific Column

Post by Support Team » Tue May 04, 2010 11:59 am

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

riccardo
Posts: 30
Joined: Wed Apr 28, 2010 10:37 pm

Re: Looping through specific Column

Post by riccardo » Tue May 04, 2010 1: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".

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Looping through specific Column

Post by Support Team » Wed May 05, 2010 8: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

riccardo
Posts: 30
Joined: Wed Apr 28, 2010 10:37 pm

Re: Looping through specific Column

Post by riccardo » Wed May 05, 2010 9:42 am

Sorry Peter, my mistake...

Thank you very much, your solution did the Job!