Applying Filter

  • Thread starter Thread starter Timo
  • Start date Start date
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
 
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)
 
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
 
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
 
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
 
Back
Top