Hi all I am trying to make a little program that when you type in a number (anydigit) it will search the xml file and display the results in a text box, i have found some code that i would like to modify, the code here has no option to type into but a drop down box. How do I make it so I have to type the number in then click search ?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using System.Xml;
namespace example
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
populateCombo();
}
private void populateCombo()
{
cmbPlatform.Items.Clear();
XmlDocument doc = new XmlDocument();
doc.Load("VideoGames.xml");
XmlNodeList nodeList = doc.SelectNodes("VGames/Game");
foreach(XmlNode node in nodeList)
if (!cmbPlatform.Items.Contains(node.SelectSingleNode("Platform").InnerText))
cmbPlatform.Items.Add(node.SelectSingleNode("Platform").InnerText);
}
private void butFilter_Click(object sender, EventArgs e)
{
XDocument xmlDoc = XDocument.Load("VideoGames.xml");
var games = from game in xmlDoc.Descendants("Game")
where game.Element("Platform").Value == cmbPlatform.SelectedItem.ToString()
select new
{
Title = game.Element("Title").Value,
Platform = game.Element("Platform").Value,
};
txtResults.Text = "";
foreach (var game in games)
{
txtResults.Text = txtResults.Text + "Title: " + game.Title + "\n";
txtResults.Text = txtResults.Text + "Platform: " + game.Platform + "\n\n";
}
if (txtResults.Text == "")
txtResults.Text = "No Results.";
}
}
}