Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#复选框“自动完成”为空_C#_.net_Autocomplete - Fatal编程技术网

c#复选框“自动完成”为空

c#复选框“自动完成”为空,c#,.net,autocomplete,C#,.net,Autocomplete,文本框的和属性允许我在文本框中使用自动完成 我直接绑定了一个datatable作为textbox的AutoCompleteSource,它工作得很好 在某些情况下,输入的单词在源代码中不可用,自动完成没有结果,因此,在这些情况下,我需要做一些其他事情 我应该如何检查自动完成结果是否为空?这里有一种方法可以使用。当输入的字符超过3个时,以下代码将在文本框的TextChanged事件中获得建议。我们去获取建议,然后检查是否有任何建议被回复。如果是,则设置自动完成CustomSource。否则,我们会

文本框的和属性允许我在文本框中使用自动完成

我直接绑定了一个datatable作为textbox的AutoCompleteSource,它工作得很好

在某些情况下,输入的单词在源代码中不可用,自动完成没有结果,因此,在这些情况下,我需要做一些其他事情


我应该如何检查自动完成结果是否为空?

这里有一种方法可以使用。当输入的字符超过3个时,以下代码将在文本框的
TextChanged
事件中获得建议。我们去获取建议,然后检查是否有任何建议被回复。如果是,则设置
自动完成CustomSource
。否则,我们会做一些事情——不管我们想做什么

private void textBox1_TextChanged(object sender, EventArgs e)
{
    TextBox t = sender as TextBox;
    if (t != null)
    {
        // Here I am making the assumption we will get suggestions after
        // 3 characters are entered
        if (t.Text.Length >= 3)
        {
            // This will get the suggestions from some place like db, 
            // table etc.
            string[] arr = GetSuggestions(t.Text);

            if (arr.Length == 0) {// do whatever you want to}
            else 
            {
                var collection = new AutoCompleteStringCollection();
                collection.AddRange(arr);

                this.textBox1.AutoCompleteCustomSource = collection;
            }
        }
    }
}