Hi...
I'm new to Ranorex and have a question about how to determine the position (index) of a column in a grid based on the Column's name.
This is for a Windows .Net application using Infragistics controls. I have a grid/table control and I don't want to hard code column index. I know the name of the column, and I want to determine it's position/index in the grid.
Any suggestions / pointers to existing documentation is appreciated. Thank you.
Jack
Dynamically determining position of column in a grid
-
- Posts: 17
- Joined: Fri Feb 12, 2010 5:33 pm
Re: Dynamically determining position of column in a grid
What is spy showing you? Does it give you columns, rows, cells?
You can write some code to loop any of those or write a Ranorex Find to find the column you want using a variable in the RanorexPath string.
So for starters I would look at the RanorexPath that is generated by RanorexSpy to the column you want to find. Then you can just find that path in code and you will have your pointer to the column. From there on you can get any information about that object you want, that RanorexSpy can see.
You can write some code to loop any of those or write a Ranorex Find to find the column you want using a variable in the RanorexPath string.
So for starters I would look at the RanorexPath that is generated by RanorexSpy to the column you want to find. Then you can just find that path in code and you will have your pointer to the column. From there on you can get any information about that object you want, that RanorexSpy can see.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
-
- Posts: 17
- Joined: Fri Feb 12, 2010 5:33 pm
Re: Dynamically determining position of column in a grid
Thanks Ciege... that helped.
Although the Cell.Element.ChildIndex returns a vlue that is not zero based, so later on when calling TERow.Cells[x] it would be off by one. Worked around by subtracting one. not sure if it is a bug or just the way that it is... in any case it works, and thanks for the help.
Although the Cell.Element.ChildIndex returns a vlue that is not zero based, so later on when calling TERow.Cells[x] it would be off by one. Worked around by subtracting one. not sure if it is a bug or just the way that it is... in any case it works, and thanks for the help.
Code: Select all
Cell TECell ="/form[@controlname='MainForm']/element[@controltypename='MdiClient']/form/container[@controlname='pWholePage']/container/container[@controlname='pIndexView']/container/element[@controltypename='TEGrid']/table/row[@accessiblename='Band 0 row 1']/cell[@accessiblename='Description']";
int CellIndex = TECell.Element.ChildIndex - 1; //must subtract one because it should be zero based
foreach (Ranorex.Row TERow in TEGrid.Rows)
{
if (TERow.Cells[CellIndex].Text == fullTEDescription)
{
TERow.Select();
break;
}
}
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Dynamically determining position of column in a grid
The Element.ChildIndex property is zero-based! However, it counts all the children of a parent element, not just cells. So, the index of a cell might be different than the value of ChildIndex if there are elements with the same parent that are no cells.jack_r_daniels wrote:Although the Cell.Element.ChildIndex returns a vlue that is not zero based,...
Use the Cell.RowIndex or ColumnIndex properties, respectively, to get the index of cells. If these element attributes do not return valid values, you might need to enabled these (computationally) expensive attributes in your code:
Ranorex.Plugin.MsaaFlavor.Instance.ExpensiveAttributesEnabled = true; Ranorex.Plugin.WpfFlavor.Instance.ExpensiveAttributesEnabled = true;Regards,
Alex
Ranorex Support Team
-
- Posts: 17
- Joined: Fri Feb 12, 2010 5:33 pm
Re: Dynamically determining position of column in a grid
Thanks for getting back to me about this... my first attempt was to use the Cell.ColumnIndex property, however it was always returning 0. So, I used the Cell.Element.ChildINdex but because the first item there is the ColumnHeader I had to adjust the return value by subtracting 1.
Thanks for letting me know about the ExpensiveAttributesEnabled properties... I'll give it a try and let you know if I get the correct result...
Jack
Thanks for letting me know about the ExpensiveAttributesEnabled properties... I'll give it a try and let you know if I get the correct result...
Jack
-
- Posts: 17
- Joined: Fri Feb 12, 2010 5:33 pm
Re: Dynamically determining position of column in a grid
That worked perfectly! What other hidden features are there?
Sorry for not sounding grateful (I am certainly grateful) but I wish this was better documented...
Jack
Sorry for not sounding grateful (I am certainly grateful) but I wish this was better documented...
Jack
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Dynamically determining position of column in a grid
I guess there are a few, most of them are usually not needed and are revealed only for persons that dare to ask questions and read the forumsjack_r_daniels wrote:What other hidden features are there?

Seriously, "hidden" features like the ExpensiveAttributesEnabled property are not in the User Guide, since there is no graphical configuration dialog to enable/disable that property, yet. I.e. you can only set this property in code.jack_r_daniels wrote:I wish this was better documented
Furthermore, this is quite a dangerous setting, since if you set this property to true, creating and evaluating RanoreXPaths will be much slower whenever such expensive properties need to be computed. So, we only want advanced users (who usually read the forums) to enable that property

Regards,
Alex
Ranorex Support Team