我只是想在我的字符串中搜索字符串,ListBox
我认为在我遇到这个问题之前我已经很沮丧了:
* *.exe中发生了“System.NotImplementedException”类型的未处理异常
附加信息:方法或操作未实现。
这是我的一段代码:
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();
}
}
}
}