Page 1 of 1

Dynamically determining position of column in a grid

Posted: Fri Feb 12, 2010 5:41 pm
by jack_r_daniels
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

Re: Dynamically determining position of column in a grid

Posted: Mon Feb 15, 2010 5:40 pm
by Ciege
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.

Re: Dynamically determining position of column in a grid

Posted: Tue Feb 16, 2010 8:21 pm
by jack_r_daniels
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.

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;
			}
		}

Re: Dynamically determining position of column in a grid

Posted: Tue Feb 23, 2010 6:36 pm
by Support Team
jack_r_daniels wrote:Although the Cell.Element.ChildIndex returns a vlue that is not zero based,...
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.

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

Re: Dynamically determining position of column in a grid

Posted: Wed Feb 24, 2010 6:36 pm
by jack_r_daniels
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

Re: Dynamically determining position of column in a grid

Posted: Wed Feb 24, 2010 6:45 pm
by jack_r_daniels
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

Re: Dynamically determining position of column in a grid

Posted: Thu Feb 25, 2010 6:38 pm
by Support Team
jack_r_daniels wrote:What other hidden features are there?
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 forums :wink:
jack_r_daniels wrote:I wish this was better documented
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.
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