Results 1 to 11 of 11

Thread: [RESOLVED] Stop immediate datagridview filter

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Resolved [RESOLVED] Stop immediate datagridview filter

    I have a datagridview which filters on a boolean field where it's false. If the user clicks on the field, the line disappears immediately I guess because it no longer satisfies the filter. Is there any way to prevent this?

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Stop immediate datagridview filter

    How do you filter the data?
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Stop immediate datagridview filter

    Code:
    tblTransactionsBindingSource.Filter = "Complete = False"
    Complete is a boolean field.

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Stop immediate datagridview filter

    So you're saying that the datagridview is not updating immediately after you set the filter property of the binding source? If that is the case, try to call bindingsource.ResetBindings(false) after you set the filter to force the DGV to update.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Stop immediate datagridview filter

    No. When complete is clicked on the dgv and then something else is clicked, the line disappears. I'd like to prevent that.

  6. #6
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Stop immediate datagridview filter

    Quote Originally Posted by projecttoday View Post
    No. When complete is clicked on the dgv and then something else is clicked, the line disappears. I'd like to prevent that.
    Yes that can happen. The attached VS2008 project replicates your issue using xml loaded into a DataTable which becomes the data source of a BindingSource connected to a DataGridView.

    Work the filter using the button and combobox with the checkbox checked and unchecked. Watch the label under the checkbox for different behaviors i.e. row disappears or the filter auto flips to match the new value of the DataGridView Checkbox column.

    In the end if you are filtered on one thing and change the value of a column which does not match the filter then you need to decide if the filter should be completely removed or in this case a Boolean toggle the filter.

    Note ignore the other columns other than the first column in the DataGridView.
    Attached Files Attached Files

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Stop immediate datagridview filter

    I'm not getting a project when I open Checkandlink in VB 2008 Express. Is this the solution file?

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

    Re: Stop immediate datagridview filter

    One option would be to call SuspendBinding on the BindingSource, but that's probably not a good idea. Another option might be change the way you set the Filter. Call the Select method of the DataTable to get all the rows that match your criteria. Create a String containing all their IDs. Create a filter expression that gets records where the ID is IN that list. Now, the records with those IDs will be displayed no matter what changes you make to them. Note that any new rows added will be filtered out though.
    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

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: Stop immediate datagridview filter

    Currently when the checkbox is checked, the row does not disappear. It disappears when another row is checked. Then that row disappears when another row is checked. Is there any way to make it so it disappears immediately (as a workaround)?

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

    Re: Stop immediate datagridview filter

    Quote Originally Posted by projecttoday View Post
    Currently when the checkbox is checked, the row does not disappear. It disappears when another row is checked. Then that row disappears when another row is checked. Is there any way to make it so it disappears immediately (as a workaround)?
    If you'd read the documentation for the DataGridViewCheckBoxColumn then you'd know why that happens and how to do what you're asking for. I've said it before and I'll say it again: always read the documentation first.
    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

  11. #11
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Stop immediate datagridview filter

    Quote Originally Posted by projecttoday View Post
    I'm not getting a project when I open Checkandlink in VB 2008 Express. Is this the solution file?
    Do not know what the problem is as I do not have Express. I created the project at home on VS2008 and then opened it at work from downloading it here in VS2010 no problem.

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