What is the correct use of DataRange.MaxRange?

Ranorex Spy, Recorder, and Studio.
carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

What is the correct use of DataRange.MaxRange?

Post by carsonw » Wed Feb 15, 2012 2:08 am

Hi there, this piece of code isn't quite behaving the way I expect:

Code: Select all

if (TestCase.Current.DataContext.CurrentRowIndex == TestCase.Current.DataRange.MaxRange)
TestCase.Current.DataContext.CurrentRowIndex is returning the correct row (1 through 6), but MaxRange (aand MinRange) both always return -1.

I'm guessing I'm using this wrong, but I'm not sure the correct way to use it. Thanks in advance! :)

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: What is the correct use of DataRange.MaxRange?

Post by Support Team » Wed Feb 15, 2012 8:46 am

Hi,

if you are setting a Data Range within your Data Source, MaxRange and MinRange are representing the limits of this Data Range.

To get the number of rows returned, you can use following code snippet:
DataSources.Get("<yourConnector>").Rows.Count
whereas <yourConnector> is the name of your Data Connector.


Regards,
Tobias
Ranorex Support Team
.
Image

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: What is the correct use of DataRange.MaxRange?

Post by carsonw » Wed Feb 15, 2012 6:08 pm

Thanks very much! I was hoping to get the binding associated with the current test, rather than having to call it by name (in case the name changes for some reason then I don't have to update the code). I'm not sure if that can be done - if not this works great.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: What is the correct use of DataRange.MaxRange?

Post by Support Team » Thu Feb 16, 2012 12:14 pm

Hi,
carsonw wrote:Thanks very much! I was hoping to get the binding associated with the current test, rather than having to call it by name (in case the name changes for some reason then I don't have to update the code). I'm not sure if that can be done - if not this works great.
If you want to use the current DataConnector for a TestCase, you could use the following line of code instead of the name of the dataconnector.
string dataConnectorName = TestCase.Current.DataContext.Source.Connector.Name;
Regards,
Peter
Ranorex Team
.
Image

carsonw
Posts: 178
Joined: Tue Nov 08, 2011 10:01 pm

Re: What is the correct use of DataRange.MaxRange?

Post by carsonw » Thu Feb 16, 2012 7:48 pm

Perfect, thanks kindly!