This is a program to show the xml in a listbox
:
public partial class Form1 : Form
{
List<string> list = new List<string>();
public Form1()
{
InitializeComponent();
LoadSprites();
list.Clear();
foreach (String str in listBox.Items)
{
list.Add(str);
}
}
private void LoadSprites()
{
XDocument xdoc = XDocument.Load("sprites.xml");
xdoc.Descendants("furnitype").Select(p => new
{
id = p.Attribute("classname").Value,
name = p.Element("name").Value
}).ToList().ForEach(p =>
{
string ci = p.name + "- " + p.id;
listBox.Items.Add(ci);
string name = p.name;
string id = p.id;
});
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(textBox1.Text.Trim()) == false)
{
listBox.Items.Clear();
foreach (string str in list)
{
if (str.StartsWith(textBox1.Text.Trim()))
{
listBox.Items.Add(str);
}
}
}
else if (textBox1.Text.Trim() == "")
{
listBox.Items.Clear();
foreach (string str in list)
{
listBox.Items.Add(str);
}
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
How can I search for the entire string? That is, do not start looking for the first letter.