query a xml file and show results in windows form

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 2
Reputation: jaystar is an unknown quantity at this point 
Solved Threads: 0
jaystar jaystar is offline Offline
Newbie Poster

query a xml file and show results in windows form

 
0
  #1
Apr 27th, 2009
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.";
        }
    }
}
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 360
Reputation: jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice 
Solved Threads: 69
jencas jencas is offline Offline
Posting Whiz

Re: query a xml file and show results in windows form

 
0
  #2
Apr 28th, 2009
You better post this one in an appropriate forum. Your code is not C++ and this is the C++ forum!!!!
If you are forced to reinvent the wheel at least try to invent a better one!

Please use code tags - Please mark solved threads as solved
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC