Filter Datagrid

  • Thread starter Thread starter Smudger
  • Start date Start date
S

Smudger

How can I place a filter on my datagrid only to view
specific records ?

The query In SQL would be:

SELECT *
FROM Orders
WHERE dispatched = X

The filter will be applied on the click event of a set of
radio buttons
 
if your basing your datgrid off a dataset (probably) you can use the .Select
method

where it would be everything AFTER your WHERE clause.

you can also use a dataview which does the same thing except you use the
RowFilter property and it takes care of error handling.

Which is nice.

so you can do. mydataset.tables(0).Select("dispachted = '" & x & "'")

or

myDv.rowFilter = "dispatched = '" & x & "'"
 
it seems that you are trying to use the variable x out of scope (it isn't
declared correctly to use it there)

try putting the private declaration (private x as string) at the top of your
form
if you want to use yes (text) you have to put it betueen "" to make it a
string
mydataset.tables(0).Select("dispatched = '" & "yes" & "'") or
mydataset.tables(0).Select("dispatched = 'yes'")

hope it helps

eric
 
ok Eric, this compiles error free but how do I display
the results of the query in my initial datagrid

I tried to fill the adapter again immediately after the
query but it doesn't display the results
 
Hi Smudger

The select creates an array of datarows.

dim myarray() as datarow = ds........... select

You can use it, but I think it is more easy in your case to use the dataview
with row filter as CJ did give you.

This is copied from MSDN
Private Sub MakeDataView()
Dim dv As DataView
dv = New DataView
With dv
.Table = DataSet1.Tables("Suppliers")
.AllowDelete = True
.AllowEdit = True
.AllowNew = True
.RowFilter = "City = 'Berlin'"
.RowStateFilter = DataViewRowState.ModifiedCurrent
.Sort = "CompanyName DESC"
End With

' Simple bind to a TextBox control
Text1.DataBindings.Add("Text", dv, "CompanyName")
End Sub

I hope this helps?

Cor
 
Thanks eric, couldn't get access to newsgroups for awhile so couldn't reply.
Thanks for covering. =)

-CJ
 
x Marks The Spot

;-)

----------------------------------------------------------------
Hi Smudger

The select creates an array of datarows.

dim myarray() as datarow = ds........... select

You can use it, but I think it is more easy in your case to use the
dataview with row filter as CJ did give you.

This is copied from MSDN
Private Sub MakeDataView()
Dim dv As DataView
dv = New DataView
With dv
.Table = DataSet1.Tables("Suppliers")
.AllowDelete = True
.AllowEdit = True
.AllowNew = True
.RowFilter = "City = 'Berlin'"
.RowStateFilter = DataViewRowState.ModifiedCurrent
.Sort = "CompanyName DESC"
End With

' Simple bind to a TextBox control
Text1.DataBindings.Add("Text", dv, "CompanyName")
End Sub

I hope this helps?

Cor

Regards - OHM# (e-mail address removed)
 
Your still not doing something right then, the datagrid automatically
updates based on the change within (caused by a Select method which raises
an event to the grid (or other bound controls) of the change

either a, your expression isn't showing any results that match, or b, your
filter expression isn't any good...

Are you sure your selecting the right tables/dataset/dataview? and is your
binding context set correctly, I mess that up all the time.

-CJ
 
mine are acting up 2 i still don't c the post from smudger (the one i
replied 2) on this news server (news.skynet.be) but it is on
new.microsoft.com, strange

eric
 
Back
Top