Applying Filter

T

Timo

I have to build dozens of simple data-entry forms in just a couple of days,
and while I'm looking for a 3rd party tool that will help me do this, I
tried the Data Form Wizard in Visual Studio, which builds a persistent
dataset object based on a chosen table or view, and produces some basic
code-behind. The generated routine listed below binds the dataset member
(here, the VISITOR table) to a grid on the form.

How and where can I modify this code to apply a filter to the VISITOR table,
e.g. all visitors whose lastname begins with the letter 'J', so that only
the J-names are shown in the grid?
Thanks
Timo

'// generated by the Data Form wizard
Public Sub LoadDataSet()

Dim objDataSetTemp As FormsWizardTest.dsvisitors
objDataSetTemp = New FormsWizardTest.dsvisitors
Try

Me.FillDataSet(objDataSetTemp)


Catch eFillDataSet As System.Exception
Throw eFillDataSet
End Try


Try
grdVISITOR.DataSource = Nothing

objdsvisitors.Clear()

objdsvisitors.Merge(objDataSetTemp)
grdVISITOR.SetDataBinding(objdsvisitors, "VISITOR")

grdVISITOR.

Catch eLoadMerge As System.Exception

Throw eLoadMerge
End Try

End Sub
 
G

Guest

Hi Timo,

If you want to apply the filter to DB query, sql query is like

SELECT * FROM VISITOR WHERE lastname LIKE ‘J%’

If you get whole data into a datatable then apply the filter, you can use
following code:

Dim dv As DataView = datatable.DefaultView
dv.RowFilter = “lastname LIKE ‘J%’â€

HTH

Elton Wang
(e-mail address removed)
 
T

Timo

Thanks, Elton. It isn't the syntax of how to create a filter that I need
help with, but where, *in the code generated by the Data Form Wizard*, the
filter should be applied, so that the grid on the form displays the matching
rows. When I apply the filter it is having no effect on the grid.
Regards
Timo
 
B

Bud Dean

Timo:

apply your filter in this area:

grdVISITOR.SetDataBinding(objdsvisitors, "VISITOR")

Create a dataview and aply the rowfilter. Then set the datasource of the
datgrid to the dataview, like Elton's example..

HTH,

bud
 
T

Timo

I had tried something like that already, but I get an error:

Dim DV As DataView
DV = objdsWebvisitors.Tables("VISITOR").DefaultView
DV.RowFilter = "lastname like 'J%'"

'// replaced this auto-generated line
'// grdWEBVISITOR.SetDataBinding(objdsWebvisitors, "VISITOR")

'// with this line:

grdWEBVISITOR.SetDataBinding(DV, "VISITOR")


The error is:

"Cannot create a child list for field VISITOR".

The .SetDataBinding method expects a string as the second argument. When the
first argument is a DataSet, the second argument is the name of the table.
But if the first argument is a DataView, what should the second argument be?

Thanks
Timo
 
T

Timo

I found out the answer-- second argument can be String.Empty
Thanks for the help.
Timo
 

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

Similar Threads

Update problem 1
Dataset NOT Updating 15
Anoying Problem 6
BindingContext problems 1
Error clearing Date fields 2
Datagrid and Clear Method Error. 1
SQLAdapter Timeout doesn't work 6
Autonumber Primary key value 1

Top