`

C#中可搜索下拉框

    博客分类:
  • VS
阅读更多

1.给下拉框赋值

            DirectoryInfo di = new DirectoryInfo(path + "xls\\干部人事档案目录");
            foreach (FileInfo file in di.GetFiles())
            {
                comboBox1.Items.Add(file.Name);
            }

 2.关键词搜索

        //关键词搜索下拉框
        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            DirectoryInfo di = new DirectoryInfo(path + "xls\\干部人事档案目录");
            string zn = comboBox1.Text;
            comboBox1.Items.Clear();
            //当在ComboBox输入内容时,内容文本是倒序输出的,光标位置始终在最前面。
            this.comboBox1.SelectionStart = this.comboBox1.Text.Length;
            foreach (FileInfo file in di.GetFiles())
            {
                if (file.Name.Contains(zn))
                {
                    comboBox1.Items.Add(file.Name);
                }
            }
        }

 3.下拉框选择事件

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string fname = comboBox1.SelectedItem.ToString();
            openExcel(path + "xls\\干部人事档案目录\\" + fname);
        }

 第2,3条需要在设计器里边加监听

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics