Hi,
Is there a way to get a row from the list filtered by SetFilterRowCell? When I filtered the list with SetFilterRowCell, the filtered list still maintain the same row index before the filtering. So, I would have to know the row index before the filter to select the row. For example, the row may have index of 201. I expect after the filtering the row index should be 0 since it becomes the first row after the filter is applied....however, i will still need to use row index 201 to select it. Is there a way to select it using the row index 0 as it appeared in the new filter list?
Thanks,
john
John,
You can select a row based on the visible index by looping through the rows and checking the IsFilteredOut property of each row. When you have found the nth row, use the actual index to select that row. For example the following code will activate and select the fifth row when a filter is applied to a grid:
currentIndex = 0 For i = 0 to swfwindow("Form1").SwfTable("ultraGrid1").GetNAProperty("Rows.Count") - 1 If swfwindow("Form1").SwfTable("ultraGrid1").GetNAProperty("Rows["+ cstr(i) +"].IsFilteredOut") = false Then currentIndex = currentIndex + 1 If currentIndex = 5 Then swfWindow("Form1").SwfTable("ultraGrid1").ActivateRow CStr(i) swfWindow("Form1").SwfTable("ultraGrid1").SelectRow CStr(i) End If End If Next
Let me know if you have any questions with this matter.
Alan
The issue is that my table has thousands of rows. It takes minutes to loop through all rows. That is the reason why I tried to filtered the table first to a smaller list, but unfortunately i can't get the row from the smaller list...
Hello,
There is a method exposed off the Rows collection that returns a array of UltraGridRow objects. You can access this with the following in QTP:
SET grid = SwfWindow("Form1").SwfTable("ultraGrid1").ObjectfRows = grid.Rows.GetFilteredInNonGroupByRows()
Beyond getting the count using Ubound(fRows), I am not sure of any way to get anything useful from this Array. If you try to access an item using fRows(0) you will get a Type mismatch error.
Hi Alan,
This is good stuff. Is there a way to get the row index # of the each item in fRows array. Thanks,
John
I wasn't able to access the items in the Array which should be the UltraGridRow objects. I am not sure why this happens and we also have no control over it as the functionality is provided by QTP and the .NET Add-In. As such this approach is limited.
Alan,
I found this thread to be helpful, but I have a couple of questions.
1. Concerning your post of Tue, Jun 30 2009 2:45 PM, couldn't an "Exit For" be used to end the loop as soon as the "currentIndex" equals the desired number, instead of looping through every row? Here's an example:
currentIndex = 0For i = 0 to SwfWindow("Company").SwfTable("ultraGrid1").GetNAProperty("Rows.Count") - 1 If SwfWindow("Company").SwfTable("ultraGrid1").GetNAProperty("Rows["& CStr(i) &"].IsFilteredOut") = False Then currentIndex = currentIndex + 1 If currentIndex = 5 Then SwfWindow("Company").SwfTable("ultraGrid1").ActivateRow CStr(i) SwfWindow("Company").SwfTable("ultraGrid1").SelectRow CStr(i) Exit For End If End IfNext
2. If I wanted to change the value of a cell for the row once it has been selected, is the following code the best method?
SwfWindow("Company").SwfTable("ultraGrid1").ActivateCell "" & i & "", "Value"SwfWindow("Company").SwfTable("ultraGrid1").SetCellData "" & i & "", "Value","0.250"
Thanks in advance!
Dennis
Dennis,
Rather than looping through the rows, there is a better approach that can be used to get the actual index of a row from the visible index. The Rows collection exposes a method GetRowAtVisibleIndex and this can be used to get the UltraGridRow object and then its Index property can be used to find the actual index from a visible index. The following code accomplishes this:
visibleIndex = CInt(swfWindow("Form1").SwfTable("ultraGrid1").Object.Rows.GetRowAtVisibleIndex(2).Index)swfWindow("Form1").SwfTable("ultraGrid1").ActivateRow CStr(visibleIndex)swfWindow("Form1").SwfTable("ultraGrid1").SelectRow CStr(visibleIndex)
For setting the value, using ActivateCell and SetCellData is the correct approach. This would look like the following:
visibleIndex = CInt(swfWindow("Form1").SwfTable("ultraGrid1").Object.Rows.GetRowAtVisibleIndex(2).Index)swfWindow("Form1").SwfTable("ultraGrid1").ActivateRow CStr(visibleIndex)SwfWindow("Form1").SwfTable("ultraGrid1").ActivateCell CStr(visibleIndex),"Name"SwfWindow("Form1").SwfTable("ultraGrid1").SetCellData CStr(visibleIndex),"Name","test"
Ravi,
Assuming that you want to apply a filter to the grid using QTP, if you have a filter row, you could use the SetFilterRowCell. If you are using header icons you can use SetFilter. You can find more details on both of these methods if you install the documentation locally. You can also get an example if you record the grid and apply a filter while recording and reference the recorded script.
Can you help me out in filtering a particular column with a certain text criteria...how can i do that?
Regards,
Ravi Salunkhe
Your solution is much more efficient. Thank you!