在streamreader中搜索过滤器c#

时间:2018-06-17 07:23:30

标签: c# search datagridview streamreader

我想通过过滤器搜索这个数据网格视图我已经搜索了很多时间来做到这一点,但是我找到的解决方案的nun解决了我的代码 (这是我用来加载数据网格视图的代码)

static public string APP_FOLDER = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Tools/Admin Tool/");
public string fileItem = ("Item.txt");

public class itemInterface
{
    public string Code { get; set; }
    public string Item { get; set; }

    public itemInterface(string key, string value)
    {
        Code = key;
        Item = value;
    }
    public itemInterface(string[] value)
    {
        Code = value[0];
        Item = value[1];
    }
}

static public void UpdateItemDataGridView(DataGridView dgv, List<itemInterface> pList)
{
    dgv.ColumnHeadersVisible = false;
    dgv.DataSource = pList;
    dgv.Columns[0].Width = 70;
    dgv.ColumnHeadersVisible = true;
}

private void Form1_Load(object sender, EventArgs e)
{
    List<itemInterface> pList = new List<itemInterface>();
    using (StreamReader sr = new StreamReader(APP_FOLDER + fileItem, Encoding.UTF8, true))
    {
        string s = String.Empty;
        while ((s = sr.ReadLine()) != null)
        {
            itemInterface l = new itemInterface(s.Split('\t'));
            pList.Add(l);
        }
    }
    UpdateItemDataGridView(dataGridView2, pList);
} 

1 个答案:

答案 0 :(得分:1)

我对搜索代码

的方式进行了罚款
 List<itemInterface> pList = new List<itemInterface>();
    using (StreamReader sr = new StreamReader(APP_FOLDER + fileItem, Encoding.UTF8, true))
    {
        string s = String.Empty;
        while ((s = sr.ReadLine()) != null)
        {
            itemInterface l = new itemInterface(s.Split('\t'));

            pList.Add(l);

        }
    }

    var pSearch = pList.FindAll(i => i.Item.ToLower().Contains(textBox12.Text.ToLower()));
    UpdateItemDataGridView(dataGridView2, pSearch);