Dynamically determining position of column in a grid

Ask general questions here.
jack_r_daniels
Posts: 17
Joined: Fri Feb 12, 2010 5:33 pm

Dynamically determining position of column in a grid

Post by jack_r_daniels » Fri Feb 12, 2010 5:41 pm

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

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Dynamically determining position of column in a grid

Post by Ciege » Mon Feb 15, 2010 5:40 pm

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.
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...

jack_r_daniels
Posts: 17
Joined: Fri Feb 12, 2010 5:33 pm

Re: Dynamically determining position of column in a grid

Post by jack_r_daniels » Tue Feb 16, 2010 8:21 pm

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

User avatar
Support Team
Site Admin
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

Post by Support Team » Tue Feb 23, 2010 6:36 pm

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

jack_r_daniels
Posts: 17
Joined: Fri Feb 12, 2010 5:33 pm

Re: Dynamically determining position of column in a grid

Post by jack_r_daniels » Wed Feb 24, 2010 6:36 pm

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

jack_r_daniels
Posts: 17
Joined: Fri Feb 12, 2010 5:33 pm

Re: Dynamically determining position of column in a grid

Post by jack_r_daniels » Wed Feb 24, 2010 6:45 pm

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

User avatar
Support Team
Site Admin
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

Post by Support Team » Thu Feb 25, 2010 6:38 pm

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