-
1 Attachment(s)
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:
Attachment 106383
I'm using visual studio 2012
-
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.
-
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 = ""
-
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.
-
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.
-
Re: Removing date filter
-
Re: Removing date filter
Quote:
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.
-
Re: Removing date filter
-
Re: Removing date filter
Show us the code that sets the filter!!
-
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
-
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
-
Solved: Removing date filter