C# 使用tableadapter windows窗体C制作自动完成文本框

C# 使用tableadapter windows窗体C制作自动完成文本框,c#,winforms,autocomplete,tableadapter,C#,Winforms,Autocomplete,Tableadapter,我有这段代码来自动完成我的搜索文本框 AutoCompleteStringCollection coll = new AutoCompleteStringCollection(); DataTableReader reader=this.customerTableAdapter.GetData().CreateDataReader(); while(reader.Read()){ coll.Add(reader.GetString(0));

我有这段代码来自动完成我的搜索文本框

AutoCompleteStringCollection coll = new AutoCompleteStringCollection();
        DataTableReader reader=this.customerTableAdapter.GetData().CreateDataReader();
        while(reader.Read()){
            coll.Add(reader.GetString(0));
        }

        search.AutoCompleteCustomSource = coll;
这是最好的表演方式吗?或者是否有一个函数可以使自动完成源直接指向列本身

此外,这段代码只过滤名字,但当我在gridview中使用这段代码时,它提供了更好的搜索能力,因此它可以捕获名字的任何部分

private void search_KeyUp(object sender, KeyEventArgs e)
    {
        string outputInfo = "";
        string[] keyWords = search.Text.Split(' ');

        foreach (string word in keyWords)
        {
            if (outputInfo.Length == 0)
            {
                outputInfo = "(Name LIKE '%" + word + "%')";
            }
            else
            {
                outputInfo += " AND (Name LIKE '%" + word + "%')";
            }
        }

        //Applies the filter to the DataView
        myView.RowFilter = outputInfo;
    }

建议请

这段代码不使用循环,它在字符串数组中填充表的一列,然后用作autoCompleteSource


根据我的说法,一切都是正确的。关键字搜索代码呢?如何将其合并到自动完成源中
            DataTable dt = this.data_allDataSet.merchandise;
        //use LINQ method syntax to pull the Title field from a DT into a string array...
        string[] postSource = dt
                            .AsEnumerable()
                            .Select<System.Data.DataRow, String>(x => x.Field<String>("name"))
                            .ToArray();

        var source = new AutoCompleteStringCollection();
        source.AddRange(postSource);
        cat_name.AutoCompleteCustomSource = source;
        cat_name.AutoCompleteMode = AutoCompleteMode.Suggest;
        cat_name.AutoCompleteSource = AutoCompleteSource.CustomSource;