Hello i have a problem in my c# project. I have a windows form that saves values from textboxes into a csv file. I then open the csv file in a datgrid where i'm supposed to search in it and highlight or filter particular rows and that is where i'm stuck.
I don't know how to filter the datagrid.

All i found on the internet is by using sql but i don't want to as i'm not connecting to sql server as i don't have a database but only one csv file.

This is what i'm using to open the file in datagrid. Now what i need is to filter for example who has surname "white".

public void openfile_Click(object sender, EventArgs e)
      {
         List<string[]> testParse = parseCSV("c:\\TestParse.csv");    
         dv = new DataView(dt);
        dataGridView1.DataSource = dv;

         dt.Columns.Add("ID", typeof(int));
         dt.Columns.Add("Surname", typeof(string));
         dt.Columns.Add("Salary", typeof(int));
         dt.Columns.Add("Administrative", typeof(string));
         dt.Columns.Add("Programmer", typeof(string));
         dt.Columns.Add("C#", typeof(string));
         dt.Columns.Add("C++", typeof(string));
         dt.Columns.Add("Pascal", typeof(string));
         dt.Columns.Add("Java", typeof(string));
         dt.Columns.Add("SQL", typeof(string)); 

         foreach (string[] row in testParse)
         {
               dt.Rows.Add(row);
            }
         dv.Sort = "Id";   //sort field required for search

      
      }


 public List<string[]> parseCSV(string path)
      {
         List<string[]> parsedData = new List<string[]>();

         using (StreamReader readFile = new StreamReader(path))
         {
            string line;
            string[] row;

            while ((line = readFile.ReadLine()) != null)
            {
               row = line.Split(',');
               parsedData.Add(row);
            }
         }

         return parsedData;
      }

RowFilter,

dv.RowFilter="ID=1";
//or
//dv.RowFilter="Id=" + varName;
//or
//dv.RowFilter="SurName like 'A%'";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.