using defaultview.rowfilter on a dataset problem

A

astro

I am trying to setup a filter for the dataset on a form as follows:

Me.Ds1.Tables("company").DefaultView.RowFilter = "city='New York'"


But nothing happens when this code is executed. The same 7k records are
available in the databindings.

What am I missing here conceptually? Should I be applying this to the
bindingManagerBase or something?

Thanks.
 
R

Ronchese

I believe your controls are binded to a datatable, which dont have Filter
actions available.

So, if you use the DefaultView, this view is autocreated and autodestroied
when the code run out of that line.

What you need to do is bind your controls to a dataview which needs to keep
itself alive with your program.

[]s
Cesar




"astro" <[email protected]> escreveu na mensagem
I am trying to setup a filter for the dataset on a form as follows:

Me.Ds1.Tables("company").DefaultView.RowFilter = "city='New York'"


But nothing happens when this code is executed. The same 7k records are
available in the databindings.

What am I missing here conceptually? Should I be applying this to the
bindingManagerBase or something?

Thanks.
 
F

Filipe Marcelino

Hi,

try

Me.Ds1.COMPANY.DefaultView.RowFilter = ""
Me.Ds1.COMPANY.DefaultView.RowFilter = "city='New York'"

Regards,
Filipe Marcelino
 
B

Bart Mermuys

Hi,

astro said:
I am trying to setup a filter for the dataset on a form as follows:

Me.Ds1.Tables("company").DefaultView.RowFilter = "city='New York'"

The DefaultView will be used if you have bound to control directly to a
DataTable or offcourse to the DefaultView. But the DefaultView will *not*
be used (for binding) if you have bound the control to a DataSet.
But nothing happens when this code is executed. The same 7k records are
available in the databindings.

What am I missing here conceptually? Should I be applying this to the
bindingManagerBase or something?

It doesn't matter to what you bind (well except for custom collection), the
bindings will internally always use a DataView, which is as explained
earlier not necessarily the DefaultView.

You can get the DataView used internally using a CurrencyManager( inherits
from BindingManagerBase ):

' It is important for the code below that you use the same
' DataSource and DataMember(without any field) as the
' ones you used for the binding.

Dim cm As CurrencyManager = DirectCast( _
BindingContext(dataSource, dataMember), _
CurrencyManager )

Dim dv As DataView = _
DirectCast( cm.List, DataView )

dv.RowFilter = "....."


HTH,
Greetings
 
A

astro

I've gotten the textboxes bound to the dataview...

getting the comboboxes bound is another story.....

Me.cboIndustry.DataSource = mDV

Me.cboIndustry.DisplayMember = "NAICSdesc"

Me.cboIndustry.ValueMember = "industryID"

Me.cboIndustry.DataBindings.Remove(Me.cboIndustry.DataBindings(0))

Me.cboIndustry.DataBindings.Add(New
System.Windows.Forms.Binding("SelectedValue", mdv, "industryID"))

yields "system.data.datarowView" in the combobox.....

Is there an easier way to do this rather then looping through the controls
and manually repointing them to the DataView? Can't I redirect the form
binder instead?

How difficult does it have to be to put one filter on a form's dataset?

(sorry - blowing off some steam)
 
A

astro

that worked !

thanks )

Bart Mermuys said:
Hi,



The DefaultView will be used if you have bound to control directly to a
DataTable or offcourse to the DefaultView. But the DefaultView will
*not* be used (for binding) if you have bound the control to a DataSet.


It doesn't matter to what you bind (well except for custom collection),
the bindings will internally always use a DataView, which is as explained
earlier not necessarily the DefaultView.

You can get the DataView used internally using a CurrencyManager( inherits
from BindingManagerBase ):

' It is important for the code below that you use the same
' DataSource and DataMember(without any field) as the
' ones you used for the binding.

Dim cm As CurrencyManager = DirectCast( _
BindingContext(dataSource, dataMember), _
CurrencyManager )

Dim dv As DataView = _
DirectCast( cm.List, DataView )

dv.RowFilter = "....."


HTH,
Greetings
 

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