時,我只是想搜索字符串在我ListBox
和我原本以爲它幾乎拍下來,直到我來到了這個問題:NotImplementedException搜索列表框
類型的未處理的異常「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();
}
}
}
}
在其中不錯誤發生線? – Ryan
請把完整的異常堆棧,不只是最後/第一行 –
@SimonMourier我沒有發佈整個例外... – g0d