Results 1 to 12 of 12

Thread: Removing date filter

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    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:

    Name:  xw9c.png
Views: 392
Size:  14.3 KB

    I'm using visual studio 2012
    Last edited by nikel; Oct 26th, 2013 at 06:33 AM. Reason: I added version

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    Re: Removing date filter

    may I upload my project?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Removing date filter

    Quote Originally Posted by nikel View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    Question Re: Removing date filter






  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Removing date filter

    Show us the code that sets the filter!!
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    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

  11. #11
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    200

    Resolved 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
  •  



Click Here to Expand Forum to Full Width