[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 773
  • Last Modified:

Dataview rowfilter does not work when looping the row

The generic code:

Dim dv As New DataView()
Dim dRow As datarow
Dim strHTML  As String

'Assuming I have ds sets here
'then create dv
dv = ds.Tables(0).DefaultView
dv.RowFilter = "ID = 1 OR ID is NULL"

For each drow in dv.Table.Rows
      -- Display here
      strHTML = strHML & drow("SomeFields")

Let's say rows in original dv (before filter) = 100 and after filter supposed to be 50.
In the for loop it is going to display 100 instead of 50 (after filter).

Filter only works if we bind data? not when actually loop thru it and display?
1 Solution
Jeff CertainCommented:
Your loop should be

for each row as datarowview in dv


What you're doing right now is looking at the underlying table with no filters or sorts applied. Kind of defeats the whole purpose of the dataview! ;)

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now