Getting row from the list filtered by SetFilterRowCell

Answered (Not Verified) This post has 0 verified answers | 10 Replies | 4 Followers Thread's RSS feed.

chehs01
Points 215
Replied On: Fri, Jun 5 2009 12:57 PM Reply

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

 

  • Post Points: 20

All Replies

Replied On: Tue, Jun 30 2009 3:45 PM Reply

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

Alan Halama
Developer Support Manager
Infragistics

  • Post Points: 20
chehs01
Points 215
Replied On: Tue, Jun 30 2009 4:00 PM Reply

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

  • Post Points: 20
Answered (Not Verified) Replied On: Wed, Jul 8 2009 2:42 PM Reply

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").Object
fRows = 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.

Let me know if you have any questions with this matter.

Alan

Alan Halama
Developer Support Manager
Infragistics

  • Post Points: 20
chehs01
Points 215
Replied On: Wed, Jul 22 2009 11:05 AM Reply

Hi Alan,

This is good stuff. Is there a way to get the row index # of the each item in fRows array. Thanks,

John

  • Post Points: 20
Replied On: Thu, Jul 23 2009 8:18 AM Reply

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

Alan Halama
Developer Support Manager
Infragistics

  • Post Points: 20
Dennis
Points 995
Replied On: Wed, Jul 29 2009 6:14 PM Reply

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 = 0
For 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 If
Next

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

  • Post Points: 20
Replied On: Wed, Aug 5 2009 10:58 AM Reply

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"

Let me know if you have any questions with this matter.

Alan

Alan Halama
Developer Support Manager
Infragistics

  • Post Points: 20
Dennis
Points 995
Replied On: Fri, Aug 7 2009 4:43 PM Reply

Alan,

Your solution is much more efficient. Thank you!

Dennis

  • Post Points: 20
Ravi Salunkhe
Points 405
Replied On: Fri, Mar 8 2013 1:02 AM Reply

Hi,

Can you help me out in filtering a particular column with a certain text criteria...how can i do that?

Regards,

Ravi Salunkhe

  • Post Points: 20
Replied On: Tue, Mar 12 2013 2:46 PM Reply

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.

Let me know if you have any questions with this matter.

Alan Halama
Developer Support Manager
Infragistics

  • Post Points: 5
Page 1 of 1 (11 items) | RSS