| | |
query a xml file and show results in windows form
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2009
Posts: 2
Reputation:
Solved Threads: 0
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.";
}
}
}![]() |
Other Threads in the C++ Forum
- Previous Thread: About pointers to data members
- Next Thread: Finding Mode of a Unsorted array.
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion convert count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





