Results 1 to 3 of 3

Thread: [RESOLVED] How to filter DataGridView

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    32

    Resolved [RESOLVED] How to filter DataGridView

    I have a form with a datagridview bound to a database that has recorded who entered data into via the windows user id.

    I am trying to filter the datagridview to only display records created by the user that is currently logged in.

    I can get the windows user name with function getusername() which returns a string.

    The field that houses the username is "staff_entering_referral"

    I am doing this but the datagridview does not update or change.

    bindingsource.filter = "staff_entering_referral = '" & getusername & "'"

    I have even tried hard coding the username to test and that doesn't work either.

    any help is greatly appreciated.

    Steve

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

    Re: How to filter DataGridView

    You could try the following where SomeValue is hard coded to begin with. This allows you to see it works or not. If it fails then something external is causing the problem. In either case the Find method will indicate if the value exists. From there use a variable value as you are now, make sure to trim the value also. Generally speaking a space at the start of the string can cause the filter to fail, not so much with a space at the end of the string.


    Code:
    Dim SomeValue As String = "Some value you know exists"
    Dim Position As Integer = -1
    
    Position = bindingsource.Find("staff_entering_referral", SomeValue)
    If Position > -1 Then
        bindingsource.Filter = String.Format("staff_entering_referral = '{0}'", SomeValue)
    Else
        MessageBox.Show(String.Format("'{0}' does not exists", SomeValue))
    End If

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    32

    Re: How to filter DataGridView

    Thank you for your reply, I just realized that I was using the wrong binding source.

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