[2005] DataGridView Filtering
I have two textbox - Name & Mobile which i use to filter customer's data in DataGridView1. When i filter the data using NAME field i get perfect results but when i use MOBILE field i want the data should filter after filtering according to NAME field and then according to MOBILE field. For example, i first filter data for all the customers whose Name starts from 'V' using NAME textbox and then i further filter these data on the basis of MOBILE so i should get result of all the customers whose name starts from 'V' and whose Mobile number is as per query in the MOBILE textbox :
My code for Name:
Code:
Private Sub name_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles name.TextChanged
CUSTOMERBindingSource.Filter = "name like '" & name.Text & "%'"
End Sub
My code for Mobile:
Code:
Private Sub mobile_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mobile.TextChanged
CUSTOMERBindingSource.Filter = "name like '" & name.Text & "%'"
CUSTOMERBindingSource.Filter = String.Format("Convert(Mobile, 'System.String') LIKE '{0}%'", mobile.Text)
End Sub
What changes should be made in the second code ? :confused:
Re: [2005] DataGridView Filtering
The filter for MOBILE should look like this
Code:
CUSTOMERBindingSource.Filter = "name like '" & name.Text & "%' AND mobile like '" & mobile.Text & "%'"
Re: [2005] DataGridView Filtering
I tried the following:
Code:
CUSTOMERBindingSource.Filter = "name like '" & name.Text & "%'" And String.Format("convert(mobile,system.string') like '" & mobile.Text & "%'")
but i am getting following error:
Quote:
Conversion from string "name like 'v%'" to type 'Long' is not valid.
Re: [2005] DataGridView Filtering
What are the column names in your datasource? Their datatype?
If your datasource contains 2 columns named "name" and "mobile", then you just use the EXACT filter as I showed you in the last post.
Re: [2005] DataGridView Filtering
the column names are "name" and "mobile" and i used ur code but that dint work ! name is 'varchar2' and mobile is 'number'.
Re: [2005] DataGridView Filtering
If you had given these info before, it would have been resolved by now.
Now try this:
Code:
Private Sub mobile_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mobile.TextChanged
Dim mobileNum As Integer = 0
Integer.TryParse(mobile.Text, mobileNum)
CUSTOMERBindingSource.Filter = "name like '" & name.Text & "%' AND mobile >= " & mobileNum
End Sub
Re: [2005] DataGridView Filtering
i tried this too but it's not giving me exact results, i mean while i type numbers in mobile.text it should filter as and when i enter any new number, for example: if i had selected all the customers whose name starts from "V" then i have list in DGV likewise, now when i enter numbers in mobile.text successively, it should filter those customers whose name starts from "V" and mobile number starts from say - 9 and then 8 and then 1 and so on... i hope u got my point !
Re: [2005] DataGridView Filtering
What does it do now?
What is it that you expect it to do?
Please give some examples...
Re: [2005] DataGridView Filtering
It does not filter the data according to mobile number entered in mobiletextbox, it just filters the data by name !
Suppose i have following dgv :
Name Mobile
----- ------
Vikki 9861054321
Vinni 9546743243
Valter 3211243 etc...
There is nametextbox where i type in "V" and i got above results. Now i type into mobiletextbox "9" and i get following results:
Name Mobile
----- ------
Vikki 9861054321
Vinni 9546743243
and when i type "5" i.e. it becomes "95" and then i get following results :
Name Mobile
----- ------
Vinni 9546743243
This is what i exactly want..
Re: [2005] DataGridView Filtering
Re: [2005] DataGridView Filtering
Re: [2005] DataGridView Filtering
Re: [2005] DataGridView Filtering
hello .... is this possible >>>?