problem binding filtered dataview to listbox

G

Guest

I'm able to get the count of the filtered rows of the dataview from within
the With view block, but when I try to bind the view to the listbox I don't
get any count within the With lb1 block and my listbox is empty. What's wrong?

Dim view As New DataView(tbl)
With view
.AllowDelete = True
.AllowEdit = True
.RowFilter = "name like '" & cb1.Text & "%'"
.RowStateFilter = DataViewRowState.ModifiedCurrent
End With
Try
With lb1
.DataSource = view
.DisplayMember = "name"
.ValueMember = "id"
End With
 
C

Cor Ligthert [MVP]

S,

How do you get that count? (Are you sure that it is not the table property).

Not important, however, why you set the binding in a try block, there cannot
be any catcheble exception be catched in that?

Cor
 
W

wd

I set a breakpoint in the first block and open up the command window to do
"? view.count" but when I'm in the second block the lb1 returns zero count.
The try block is a remnant of older code that I had modified but left the
try there.
 
C

Cor Ligthert [MVP]

Wd,

Did you ever use a right click on the item name, than quick watch, I have
more trust in that one.

As the code in the second part is, beside that try catch, is it should be
in my opinion right if there are rows in the dataview.

Cor
 
G

Guest

I checked out the watch and it shows a value of 16 for the
DataViewRowState.ModifiedCurrent in the view block, but inside the lb1 block
if I check the count for view it is 0. I don't understand what's wrong. I
cleaned up the code and tried to again but still doesn't help:

Dim view As New DataView(tbl)
With view
.AllowDelete = True
.AllowEdit = True
.RowFilter = "name like '" & cb1.Text & "%'"
.RowStateFilter = DataViewRowState.ModifiedCurrent
End With
With lb1
.DataSource = view
.DisplayMember = "name"
.ValueMember = "id"
End With
 

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