|
-
Oct 26th, 2013, 06:32 AM
#1
Thread Starter
Addicted Member
Removing date filter
Hello, I have a datetimepicker on a toolstripbox. Filtering works fine. I created a button to reset datagridview but it doesn't work. Here's my code:
Code:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim resetBtn = New Button With {.Text = "S", .Width = 20}
Dim dtp = New DateTimePicker With {.Format = DateTimePickerFormat.Short, .Width = 80}
'TODO: This line of code loads data into the 'MakbuzDataSet.makbuzT' table. You can move, or remove it, as needed.
Me.MakbuzTTableAdapter.Fill(Me.MakbuzDataSet.makbuzT)
MakbuzTDataGridView.Dock = DockStyle.Bottom
Me.SavePending = True
AddHandler dtp.ValueChanged, AddressOf DateTimePicker1_ValueChanged
FillByTest08ToolStrip.Items.Add(New ToolStripControlHost(dtp))
FillByTest08ToolStrip.Items.Add(New ToolStripControlHost(resetBtn))
End Sub
Private Sub resetBtn(sender As Object, e As EventArgs)
MakbuzTBindingSource.Filter = ""
MakbuzTDataGridView.DataSource = MakbuzTBindingSource
MakbuzTBindingNavigator.BindingSource = MakbuzTBindingSource
MakbuzTBindingSource.RemoveFilter()
End Sub
And a screenshot:

I'm using visual studio 2012
Last edited by nikel; Oct 26th, 2013 at 06:33 AM.
Reason: I added version
-
Oct 26th, 2013, 06:40 AM
#2
Re: Removing date filter
What do you mean it doesn't work? What do you expect to happen and what actually happens? To clear the filter you either set the Filter to Nothing or an empty String or you call RemoveFilter; not both and not anything else.
-
Oct 26th, 2013, 06:46 AM
#3
Thread Starter
Addicted Member
Re: Removing date filter
Thanks for the reply. Yes I want to clear filter but nothing happens. This code can't do it:
Code:
MakbuzTBindingSource.RemoveFilter()
and this:
Code:
MakbuzTBindingSource.Filter = Nothing
and this:
Code:
MakbuzTBindingSource.Filter = ""
Last edited by nikel; Oct 26th, 2013 at 07:31 AM.
-
Oct 26th, 2013, 07:43 AM
#4
Re: Removing date filter
All three of them do it. I asked a question in my previous post and I asked it for a reason, so you should probably answer it. If none of those three lines of code does what you expect then your expectations are unreasonable. You're doing something wrong so we need a FULL and CLEAR explanation. For a start, you talk about clearing the Filter but there's no indication in that code that you ever set it in the first place.
-
Oct 26th, 2013, 08:00 AM
#5
Re: Removing date filter
To prove my point, I just threw together this test: a form with four Buttons, a DataGridView and a BindingSource with this code:
Code:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim table As New DataTable
With table.Columns
.Add("ID", GetType(Integer))
.Add("Name", GetType(String))
End With
With table.Rows
.Add(1, "Peter")
.Add(2, "Paul")
.Add(3, "Mary")
End With
BindingSource1.DataSource = table
DataGridView1.DataSource = BindingSource1
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
BindingSource1.Filter = "Name LIKE 'P%'"
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
BindingSource1.Filter = String.Empty
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
BindingSource1.Filter = Nothing
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
BindingSource1.RemoveFilter()
End Sub
End Class
Click Button1 and you'll see Mary disappear because it's filtered out. Click any of the other Buttons and you'll see it reappear as the filter is removed.
-
Oct 26th, 2013, 08:03 AM
#6
Thread Starter
Addicted Member
-
Oct 26th, 2013, 08:29 AM
#7
Re: Removing date filter
 Originally Posted by nikel
may I upload my project?
You can upload it if you want but I don't download projects except as a last resort and we haven't reached that stage yet. You're still yet to answer my question and you certainly haven't provided a FULL and CLEAR explanation. I can't speak for others but I expect you to put a bit of time and effort into this before you just sit back and let us do all the work by downloading, extracting, opening, examining and running your project to find something that you wouldn't explain properly.
-
Oct 26th, 2013, 08:56 AM
#8
Thread Starter
Addicted Member
Re: Removing date filter
-
Oct 26th, 2013, 09:03 AM
#9
Re: Removing date filter
Show us the code that sets the filter!!
-
Oct 26th, 2013, 09:07 AM
#10
Thread Starter
Addicted Member
Re: Removing date filter
Code:
Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
Console.WriteLine(CType(sender, DateTimePicker).Value.ToShortDateString)
Me.MakbuzTBindingSource.Filter = "tarih = '" & CType(sender, DateTimePicker).Value.ToShortDateString & "'"
Me.Refresh()
End Sub
-
Oct 26th, 2013, 09:18 AM
#11
Re: Removing date filter
I found the problem... the reset button is being added dynamically... but it's click event IS NEVER HANDELD! ... the sub that does the reset does NOT have a handles clause on it, nor does the OP ever use AddHandler to wire it up. In short the filter isn't being reset because IT IS NEVER BEING CALLED.... a simple break point and stepping through the code (or not when the break point in the reset is never hit bevcause the event wasn't handled) ... would have soved the mystery long ago.
-tg
-
Oct 26th, 2013, 09:44 AM
#12
Thread Starter
Addicted Member
Solved: Removing date filter
Last edited by nikel; Oct 26th, 2013 at 09:45 AM.
Reason: I added one more link
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|