|
-
Jun 28th, 2007, 02:30 PM
#1
Thread Starter
Hyperactive Member
[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 ?
-
Jun 28th, 2007, 03:43 PM
#2
Re: [2005] DataGridView Filtering
The filter for MOBILE should look like this
Code:
CUSTOMERBindingSource.Filter = "name like '" & name.Text & "%' AND mobile like '" & mobile.Text & "%'"
-
Jun 29th, 2007, 02:26 AM
#3
Thread Starter
Hyperactive Member
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:
Conversion from string "name like 'v%'" to type 'Long' is not valid.
Last edited by LuxCoder; Jun 29th, 2007 at 02:31 AM.
-
Jun 29th, 2007, 01:33 PM
#4
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.
-
Jun 29th, 2007, 01:52 PM
#5
Thread Starter
Hyperactive Member
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'.
-
Jun 29th, 2007, 02:03 PM
#6
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
-
Jun 29th, 2007, 03:09 PM
#7
Thread Starter
Hyperactive Member
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 !
-
Jun 29th, 2007, 03:15 PM
#8
Re: [2005] DataGridView Filtering
What does it do now?
What is it that you expect it to do?
Please give some examples...
-
Jun 29th, 2007, 03:50 PM
#9
Thread Starter
Hyperactive Member
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..
Last edited by LuxCoder; Jul 3rd, 2007 at 02:32 PM.
-
Jul 3rd, 2007, 02:35 PM
#10
Thread Starter
Hyperactive Member
Re: [2005] DataGridView Filtering
-
Sep 11th, 2007, 05:37 AM
#11
Thread Starter
Hyperactive Member
Re: [2005] DataGridView Filtering
-
Oct 29th, 2009, 03:36 AM
#12
Thread Starter
Hyperactive Member
Re: [2005] DataGridView Filtering
-
Oct 31st, 2009, 01:08 PM
#13
Thread Starter
Hyperactive Member
Re: [2005] DataGridView Filtering
hello .... is this possible >>>?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|