none
problem in searching a particular string from the rows displayed in datagridview RRS feed

  • Question

  •  Hi,

    I have a problem while searching a particular string from the rows displayed in  datagridview.Datagridview contains data like "
    1st row -00 C3 17 67
    2nd row-89 B4 56
    3rd row 89 C3 17 89 78 45

    but now problem is if the user enters "C3 17" string  for search the results should display 1st and 3rd rows
    So  I am using the following code but this does not work and even i used string.Contains this is also not working.

    My Code:

     DataView
    dv = new DataView(datatable1, "[Data]" + " like '% " + TextBox1.Text.ToString().Trim() + " %'", "", DataViewRowState.CurrentRows);

    datatable2.Merge(dv.ToTable(), true);



    Pls help in finding the solution for this.

    Thanks
    Kusuma


    Kusuma
    • Edited by Kusuma2 Monday, December 22, 2008 11:53 AM
    Monday, December 22, 2008 10:37 AM

All replies

  • In my eyes the following "[" Data "]" should either be "[Data]" or "[" + Data + "]"
    Ewald
    Monday, December 22, 2008 10:46 AM
  • Sorry Ewald,it was a mistake form myside .I have corrected it .
    Kusuma
    Monday, December 22, 2008 11:54 AM
  • Can you provide more information what is not working.


    Ewald
    Monday, December 22, 2008 12:03 PM

  • Follwoing are the rows dsipalyed in datagriwd veiw
    1st row -      00 C3 17 67
    2nd row-      89 B4 56
    3rd row        89 C3 17 89 78 45

    The above code gives zero rows.I want rows containg the search string("C3 17")
    If the sreach string is "C3 17" then i should get 1st and 3rd rows as result.
    Basically its filtering of rows.

    Kusuma
    Monday, December 22, 2008 12:49 PM
  • I use the following test case, which seems to be the same as you describe, does work. Maybe the example code can give you a hint where the problem can be.

    Try (but it is just a wild guess) to change the '%' into '*'.

    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Text;  
    using System.Data;  
     
    namespace ConsoleApplication1  
    {  
        class Program  
        {  
            static void Main(string[] args)  
            {  
                DataTable datatable1 = new DataTable();  
                datatable1.Columns.Add("data");  
     
                DataTable datatable2 = new DataTable();  
                datatable2.Columns.Add("data");  
     
                datatable1.Rows.Add(new object[] { "89 C3 17 89 78 45" });  
     
                DataView dv = new DataView(datatable1, "[Data]" + " like '% " + "C3 17" + " %'""", DataViewRowState.CurrentRows);  
     
                datatable2.Merge(dv.ToTable(), true);  
     
                Console.WriteLine(datatable2.Rows.Count);  
            }  
        }  
    }  
     

    Ewald
    • Proposed as answer by Manoj Manohar Monday, December 29, 2008 6:44 AM
    Monday, December 22, 2008 1:35 PM
  • Thanks Ewald :-),it worked for me.
    Kusuma
    • Proposed as answer by Manoj Manohar Monday, December 29, 2008 6:43 AM
    Tuesday, December 23, 2008 11:32 AM