Results 1 to 4 of 4

Thread: filter DGV

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2006
    Posts
    176

    filter DGV

    Hi All.
    In ToolStrip of DGV form I have DateFromDateTimePicker and DateToDateTimePicker. I would lke to filter DVG by values of these DateTimePicker.
    Thanks.
    Last edited by eugz; Oct 27th, 2009 at 03:44 PM.

  2. #2
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Somewhere else today
    Posts
    355

    Re: filter DGV

    How have you bound the DGV.

    I have done this sort of thing and the way I did was to add an SQL statement to the TABLEADAPTER where I added the filter points which you do within the Dataset Designer. Having bound the DATABINDINGSOURCE to the DGV, I filtered it thus:

    Code:
    Private Sub FilterData()
    
    me.tableadpter.fillby(dataset.recordset, datefrom,dateto)
    
    EndSub
    This would fill the datagrid with the required info.

    Computerman.
    It was much easier in VB6, but I am now liking Vb.Net alot more.

  3. #3
    Hyperactive Member
    Join Date
    Jun 2009
    Posts
    307

    Re: filter DGV

    You can apply a dataview to your dataset and use RowFilter to filter the data. Something like this:

    Code:
    ' This uses the DateTimePicker to select start and ending dates
    Dim mStart As DateTime = dtpStart.Value
    Dim mEnd As DateTime = dtpEnd.Value
    '
    dv.Sort = "TransDate"
    dv.RowFilter = String.Format("TransDate >= #{0:M/dd/yyyy}# AND TransDate <= #{1:M/dd/yyyy}#", mStart, mEnd)

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

    Re: filter DGV

    You imply that you've already got a BindingSource bound to your grid. In that case you should have just set the Filter property of that BindingSource. It's exactly this sort of thing that the BindingSource exists for.
    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

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