Results 1 to 13 of 13

Thread: [2005] DataGridView Filtering

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    [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 ?

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] DataGridView Filtering

    The filter for MOBILE should look like this
    Code:
    CUSTOMERBindingSource.Filter = "name like '" & name.Text & "%' AND mobile like '" & mobile.Text & "%'"

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    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.

  4. #4
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    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'.

  6. #6
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    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 !

  8. #8
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2005] DataGridView Filtering

    What does it do now?
    What is it that you expect it to do?
    Please give some examples...

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    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.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] DataGridView Filtering

    Any help ???

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] DataGridView Filtering

    Please help !!!

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] DataGridView Filtering

    anyone?

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    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
  •  



Click Here to Expand Forum to Full Width