Hi,
I have an UltraGrid with multiple rows and 2 columns. Out of these 2 columns 1 is a read-only and other one is editable. Using Coded UI I need to write into the editable column of a particular row (Will define this row by the 1st column).
Also I was looking documentation / tutorials regarding using Coded UI with Infragistics controls (especially grids and combo-boxes) but could not find any. Could you please point me to some ?
Hello Abhinav,
First of all, I will answer your second question. There is online documentation for Infragistics Coded UI Test Extension. Follow the next link to overview of this extension http://help.infragistics.com/Doc/WinForms/current/CLR4.0/?page=Coded_UI_Test_Extension_Overview.html. You can also check this link, where is shown how you can use Coded UI Test Extension to edit a cell in the UltraGrid.
Regarding your second question I am not sure if I understand what your issue is. Can you please try to describe in details what happens at your side when you try to edit the cell’s value?
Looking forward to your reply.
Hey,
Thanks for the link. My query is in case the number of rows is not fixed and thus recording will not be a viable option. I need to fetch a specific row and then edit that row. For example my grid has 2 columns 'Animal' and 'Population'. The animals can be of any number and any order. Now I want to edit the population of a specific Animal say 'Cat'. How do I access that specific element/row ?
One possible way is to iterate through all the rows in the grid and check the value of the cells in the first column. If the value match the one you need click on the cell in the same row in the second column and set its value. Please check this thread in our forum, where was discussed and shown how you can iterate through all the rows in a grid and get the cells’ values. When you get the cell value you can check it against the one you need. If the value match the one you need you can get the AutomationElement of the cell in the next column, click on it and set its text.
Here is a sample method doing all this:
public void SetCellValue(){ UITestControl uIColScrollRegion0RowSTree = this.UIForm1Window.UIForm1Client.UIUltragridCustom.UIDataAreaCustom.UIColScrollRegion0RowSTree; UltraUiaEdit uIUltragrid_EmbeddableEdit = this.UIForm1Window.UIUltraGrid1Window.UIUltragrid_EmbeddableEdit;
int rowIndex = 0; AutomationElement containerAutomationElement = uIColScrollRegion0RowSTree.NativeElement as AutomationElement; AutomationElement rowAutomationElement = null; ItemContainerPattern containerPattern = containerAutomationElement.GetCurrentPattern(ItemContainerPattern.Pattern) as ItemContainerPattern; rowAutomationElement = containerPattern.FindItemByProperty( null, AutomationElement.AutomationIdProperty, rowIndex.ToString()); while (rowAutomationElement != null) { // get the collection of cell automation elements AutomationElementCollection cellsAutomationElements = rowAutomationElement.FindAll(TreeScope.Children, Condition.TrueCondition);
// get the automation element for the cell in first column AutomationElement cellAutomationElement = cellsAutomationElements[0];
// Scroll the cell into view ScrollItemPattern scrollPattern = cellAutomationElement.GetCurrentPattern(ScrollItemPattern.Pattern) as ScrollItemPattern; scrollPattern.ScrollIntoView();
// use the ValuePattern to get the Value. ValuePattern valuePattern = cellAutomationElement.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; var cellValue = valuePattern.Current.Value.ToString();
// check the cell value if (cellValue == "Cat") { // get the automation element for the cell in second column AutomationElement nextCellAutomationElement = cellsAutomationElements[1];
// get clickable point on the cell in second column Point poinToClick = nextCellAutomationElement.GetClickablePoint();
// click on the cell Mouse.Click(poinToClick);
// set the cell Text uIUltragrid_EmbeddableEdit.Text = this.RecordedMethod1Params.UIUltragrid_EmbeddableEditText;
// get clickable point on the cell in the first column poinToClick = cellAutomationElement.GetClickablePoint();
break; }
// get the next row rowIndex++; rowAutomationElement = containerPattern.FindItemByProperty( null, AutomationElement.AutomationIdProperty, rowIndex.ToString()); }}
Please let me know if you need any additional information.