468,256 Members | 1,417 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,256 developers. It's quick & easy.

DataView RowFiltering

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
May 17 '06 #1
7 1323
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
May 17 '06 #2
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")) & "'"
> 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
Bernie

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in
news:et*************@TK2MSFTNGP04.phx.gbl:
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


May 17 '06 #3
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

"Bernie Hunt" <bh***@optonline.net> schreef in bericht
news:Xn*******************************@207.46.248. 16... 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")) & "'"
>> 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
Bernie

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in
news:et*************@TK2MSFTNGP04.phx.gbl:
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

May 17 '06 #4
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
Cor Ligthert [MVP] wrote:
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


May 17 '06 #5
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
"Bernie" <bh***@optonline.net> schreef in bericht
news:11*********************@38g2000cwa.googlegrou ps.com...
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
Cor Ligthert [MVP] wrote:
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

May 17 '06 #6

"Bernie" <bh***@optonline.net> wrote in message
news:11*********************@38g2000cwa.googlegrou ps.com...
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
Cor Ligthert [MVP] wrote:
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


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
May 17 '06 #7
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
May 18 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Aniket Sule | last post: by
13 posts views Thread by Steve | last post: by
5 posts views Thread by enceladus311 | last post: by
reply views Thread by kermitthefrogpy | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.