how to find row(s) containing a string (in RowCollection)?

Best practices, code snippets for common functionality, examples, and guidelines.
User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3908
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

how to find row(s) containing a string (in RowCollection)?

Post by odklizec » Wed Mar 18, 2015 3:55 pm

Hi folks,
Is there an elegant way to find row(s) containing a string (in RowCollection)? I would like to avoid using "foreach" loop (due to number of rows).

I hoped for something like DataRowCollection.Find but there seems to be no method like this available for Ranorex RowCollection? Is there a way to convert Ranorex RowCollection to DataRowCollection?

Eventually, I've read a post on similar subject, where was mentioned LINQ (this post). I was able to add LINQ reference to my project, but that's it ;) I'm not quite sure where to start? Still learning my way around the C#.

Here is my code to create CSV data connector with propTableRowsCSV rowcollection, in which I would like to find particular row(s) without using foreach loop.
//create CSV data connector
string connector = "CSVConnector";
	
//get data from CSV file
Ranorex.Core.Data.CsvDataConnector csvConnector = new Ranorex.Core.Data.CsvDataConnector(connector,csvOutputPath,true);
csvConnector.SeparatorChar = ',';
Ranorex.Core.Data.ColumnCollection propTableColumnsCSV = new Ranorex.Core.Data.ColumnCollection();
Ranorex.Core.Data.RowCollection propTableRowsCSV = new Ranorex.Core.Data.RowCollection(propTableColumnsCSV);

//load CSV connector
csvConnector.LoadData(out propTableColumnsCSV, out propTableRowsCSV);
Thanks in advance!
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Benwa
Certified Professional
Certified Professional
Posts: 12
Joined: Thu Mar 05, 2015 4:33 pm
Location: New Brunswick, Canada

Re: how to find row(s) containing a string (in RowCollection)?

Post by Benwa » Wed Mar 18, 2015 4:32 pm

LINQ is definitely a nice way to go about it. I have quite a few examples I could share with you once I get home later today (Currently at work.) but I'm just trying to remember if I've used it in RanoreX before or not.

I know I used it in a few C# applications that I created and used LINQ to pull methods and variables from the assembly of my RanoreX project.

I'll post more information later, once I get home. Maybe I'll go grab the code on my lunch for you! Unless someone else beats me to the answer :)

Cheers,
Ben

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3908
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: how to find row(s) containing a string (in RowCollection)?

Post by odklizec » Wed Mar 18, 2015 4:40 pm

Hi Ben,

Thanks very much! I really appreciate it ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Benwa
Certified Professional
Certified Professional
Posts: 12
Joined: Thu Mar 05, 2015 4:33 pm
Location: New Brunswick, Canada

Re: how to find row(s) containing a string (in RowCollection)?

Post by Benwa » Wed Mar 18, 2015 7:16 pm

Bah, sadly all the examples I would have to share are for XML. (I noticed yours was for CSV a bit too late!)

I did run into this article if you haven't already: http://blogs.msdn.com/b/ericwhite/archi ... ables.aspx

It's a bit old, so I'm not sure if it still works the same way or not. Could be a good clue on where to go next.

I also don't mind sharing my Linq code for XML if you wanted to see it, it might help you go in the right direction. I have some simple queries that could be nice to look at.

I have to say that avoiding a foreach loop probably won't work though. With Linq you can put all your rows with the criteria that you specify into a variable, but you'll still have to loop through if you want to pull data out of it. I'm no Linq expert, and could totally be wrong! I've just used it a lot a few months ago to create an application that can merge Ranorex reports together.

My apologies!
Ben

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3908
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: how to find row(s) containing a string (in RowCollection)?

Post by odklizec » Thu Mar 19, 2015 8:30 am

Hi Ben,

No problem. Thanks for your effort! For now, I will go with the foreach loop and see how much it will slow the tests down. I will check the LINQ option later ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration