[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
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
Re: How to filter DataGridView
Thank you for your reply, I just realized that I was using the wrong binding source.