DataView RowFiltering

B

Bernie Hunt

I'm having trouble getting rowfiltering to work on my dataview. I have
two dataviews, one with a list of shows (dvAllShows) and the other with a
list of shows attended by a person(dvAttendedShows). I want to walk
through all the possible shows, checking if the person attended that
show, by seeing if there is a record that contains that ShowID.

For Each drAllShows In dvAllShows.Table.Rows
filterString = "Show = '" & CStr(drAllShows("ShowID")) & "'"
dvAttendedShows.RowFilter = filterString

If dvAttendedShows.Table.Rows.Count = 1 Then
clbAttendeeShows.Items.Add(drAllShows("ShowName"), True)
Else
clbAttendeeShows.Items.Add(drAllShows("ShowName"), False)
End If
Next

The Show and ShowID columns are integers, but using '' around the value
or not produces the same not working solution.

Each time the RowFilter line is executed, all the rows in dvAttended stay
exposed.

Any suggestions?

Thanks,
Bernie
 
C

Cor Ligthert [MVP]

Bernie,
For Each drAllShows In dvAllShows.Table.Rows
This means the same as
For each datarow in the complete datatable from dvAllShows

You probably need something as

For each drvAllShows as DataRowView in dvAllShows

I hope this helps,

Cor
 
B

Bernie Hunt

Cor,

That's not where the problem is. I need all of the rows in the
dvAllShows. It's the vbAttended shows which I need to filter each time I
process a row in dvAllShows.

dvAllShows is completely different data than dvAttendingShows. They come
from different tables in the db, but they have a common key.

How do I get the filter of dvAttendingShows to work?

For Each drAllShows In dvAllShows.Table.Rows
filterString = "Show = '" & CStr(drAllShows("ShowID")) & "'"
If dvAttendedShows.Table.Rows.Count = 1 Then
clbAttendeeShows.Items.Add(drAllShows("ShowName"), True)
Else
clbAttendeeShows.Items.Add(drAllShows("ShowName"), False)
End If
Next


Bernie
 
C

Cor Ligthert [MVP]

Bernie,
That's not where the problem is. I need all of the rows in the
dvAllShows. It's the vbAttended shows which I need to filter each time I
process a row in dvAllShows

It are not all the rows in the dvAllShows it are (normally) much more.

It are all the rows in the datatables which you are using.

This code (you use it more) is without sense because the rowfilter does
nothing.

Cor
 
B

Bernie

Cor,

Maybe I'm not understanding. These two dataviews are attached to two
completely different tables. Let me take this out of the context of the
loop.

I have a dataview. I count the records in the dataview and there are 5.
I filter the dataview and then count the records ands still have 5. Why
doesn't that filter work?

Messagebox.Show(dvAttendedShows.Rows.Count) ' returns 5
filterString = "Show = '" & CStr(drAllShows("ShowID")) & "'"
dvAttendedShows.RowFilter = filterString
Messagebox.Show(dvAttendedShows.Rows.Count) ' returns 5

This should have decreased the number of rows in the dataview, but it
doesn't.

Is there something that I'm missing to implement the filter? Or maybe
does the Rows.Count property always return all the rows and not just
the filtered?

Bernie
 
C

Cor Ligthert [MVP]

Bernie,

I don't have the names of your original tables so I create a sample here.

Suppose you have a datatable
dtBernie
And you create a new dataview of that
dim dvBernie as new DataView(dtBernie)

Than is
dvBernie.Table the same as dtBernie

dvBernie.Table is no dataview it is a datatable.

And that is in your code,

Therefore is probably what you want in my first answer.

for each drv as DataRowView in dvBernie

Next

I hope that this explains it.

Cor
 
J

JensB

Bernie said:
Cor,

Maybe I'm not understanding. These two dataviews are attached to two
completely different tables. Let me take this out of the context of the
loop.

I have a dataview. I count the records in the dataview and there are 5.
I filter the dataview and then count the records ands still have 5. Why
doesn't that filter work?

Messagebox.Show(dvAttendedShows.Rows.Count) ' returns 5
filterString = "Show = '" & CStr(drAllShows("ShowID")) & "'"
dvAttendedShows.RowFilter = filterString
Messagebox.Show(dvAttendedShows.Rows.Count) ' returns 5

This should have decreased the number of rows in the dataview, but it
doesn't.

Is there something that I'm missing to implement the filter? Or maybe
does the Rows.Count property always return all the rows and not just
the filtered?

Bernie

Maybe this is a stupid question, but is the ShowID an integer or string ?
In case it is an integer, try with this one:
filterString = "Show = " & drAllShows("ShowID")
Jens
 
B

Bernie Hunt

Cor and Jens,

Thanks for your help. I found my problem today. My method of testing was
fouled. I was using

Messagebox.Show(dvAttendedShows.Rows.Count)

to see how many rows were in the dataView. When in fact this show how many
rows are in the total dataView. To see the number of rows in the filtered
dataView I should have been using

Messagebox.Show(dvAttendedShows.Count)

It works much better when you get the syntax right, hahahaha.

Thanks again!

Bernie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top