搜索ListBox时出现NotImplementedException

时间:2012-12-16 18:12:24

标签: c# listbox

我只是试图在我的ListBox中搜索字符串,而且在我遇到这个问题之前我认为我已经非常小心了:

  

未处理的类型' System.NotImplementedException'发生在 * * .exe

中      

附加信息:未实施方法或操作。

这是我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace *****
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            add();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            search();
        }
        public void search()
        {
            if (textBox2.Text == string.Empty)
            {
                MessageBox.Show("Must enter value");
            }
            else
            {
                string toFind = textBox2.Text;
                if (toFind != string.Empty)
                {
                    int search = listBox1.FindString(toFind);
                    if (search != -1)
                    {
                        listBox1.SetSelected(search, true);
                    }
                    else
                    {
                        MessageBox.Show("Could not find "+toFind);
                    }
                }
            }
        }
        public void add()
        {
            if (textBox1.Text == string.Empty)
            {
                MessageBox.Show("Must enter value");
            }
            else
            {
                listBox1.Items.Add(textBox1.Text);
            }
            textBox1.Clear();
        }
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Enter)
            {
                add();
            }
        }
        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                search();
            }
        }

    }
}

1 个答案:

答案 0 :(得分:0)

在整个项目中搜索以下内容:

throw new NotImplementedException();

并对其进行评论;)