How to find a row in table using Cell Value

Ranorex Studio, Spy, Recorder, and Driver.
pjaddu
Posts: 4
Joined: Tue Dec 01, 2009 6:30 am

How to find a row in table using Cell Value

Post by pjaddu » Mon Dec 07, 2009 3:25 pm

Hello ,

I want to find a row in the Table using a cell value . I am able to do it iterating through each row and matching the each cell value .. But this is time consuming .

So i would like to know whether is there any other way to find out a Row using cell value directly instead of looping .

Please send a sample code for that too.

Regards,
Phani

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

Re: How to find a row in table using Cell Value

Post by Support Team » Tue Dec 08, 2009 8:00 pm

pjaddu wrote:So i would like to know whether is there any other way to find out a Row using cell value directly instead of looping.
Well, that depends on the technology of the application. For example, if the table is a .NET Windows Forms control, you can use Control.InvokeRemotely to use one of the control's internal methods to search for the right row. In general, though, searching for the cell by iterating the rows will be the only solution.

However, there are ways you could speed up the searching for the cell value. Could you please post a snapshot of your application and the code you are using to loop the rows in the table? I can then give you more hints on how to optimize your code.

You might also want to read the following post covering methods to speed up search time in tables:
http://www.ranorex.com/forum/wpf-listvi ... t1015.html

Regards,
Alex
Ranorex Support Team

pjaddu
Posts: 4
Joined: Tue Dec 01, 2009 6:30 am

Re: How to find a row in table using Cell Value

Post by pjaddu » Wed Dec 09, 2009 6:01 am

Hello Alex ,
I am using .NET and the Grid of Devexpress. When i recorded the opertaion , it recongnizes Grid as TABLE.

No i want to identify a row using cell text i.e on Table now . Please find the Code for the same.

public static void FindRowinGridusingID()
{
bool blnRowFound =false;
int RowIndex=0;
Table tableUsers= Test_ComboRepository.Instance.FormForm2.tableUsers ;

foreach(Row rowUsers in tableUsers.Rows )
{

foreach(Cell celluserAttribute in rowUsers.Cells)
{
if(celluserAttribute.Text.Trim()=="111_12")
{
blnRowFound=true;
break;
}
}
if(blnRowFound)
{
break;
}
else
{
RowIndex++;
}
}

if(blnRowFound)
{
Report.Success("Row is found with Cell values as :111_12");
}
else
{
Report.Failure("No Row exists with that ID ");
}
}

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

Re: How to find a row in table using Cell Value

Post by Support Team » Thu Dec 10, 2009 9:45 am

As described in the post I mentioned before (http://www.ranorex.com/forum/wpf-listvi ... t1015.html), you can wrap a CacheSessionContext around the code accessing the table. That way, all rows/cells will only be read once from the application (slow) and afterwards all values will be read from the cache (very fast). Consequently, as long as the CacheSessionContext is active, you will always get the same(!) values from the cache, i.e. Ranorex won't recognize updates to the table.

The other possibility is to use the grid control's internal methods to search for the right cell and retrieve the index of the row using Control.InvokeRemotely. When you know the index, you can easily get the right Ranorex.Row using its index. Or you can just get all the data you want from the row inside the delegate invoked by the Control.InvokeRemotely method.
Read the following blog on how to use Control.InvokeRemotely: http://www.ranorex.com/blog/transfering ... et-control. Please, consult the documentation of the DevExpress grid control for a method that searches for a cell using its value.

Regards,
Alex
Ranorex Support Team