Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Data in C# 2005

Status
Not open for further replies.

ppuddick

ISP
Nov 15, 2002
56
GB
Hello all,

First of all I'm quite new when it comes to development so please bear with me.

I have a winforms app written in C# 2005 Express Edition. When the app starts it reads an xml document and then populates the a combobox with a node entry from the XML file. This works fine - took me ages to work it out but thats working :)

Now, I have a load of other controls on my winform - labels, textboxes, etc. I would like to achieve this.

When the user selects an item from the combobox dropdown list all other controls on the winform are then populated with the corresponding data from that node, it's siblings and children nodes.

I've been doing some research for a while on this and I'm pulling my hair out. If it helps I have put the code below so that you know exactly what I'm going on about ::

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;

namespace XmlApp
{
public partial class MainApp : Form
{

public MainApp()
{
InitializeComponent();

// Open the xml document
try
{
XmlDocument docxml1 = new XmlDocument();
docxml1.Load("information.xml");
// Get list of elements whose names are "model"
XmlNodeList printermodel = docxml1.GetElementsByTagName("printer");
//retrieve the name of each model and put in the comboBox
for (int i = 0; i < copiermodel.Count; i++)
this.cboModels.Items.Add(printermodel.Attributes["Model"].InnerText);

}

// If the .xml document cannot be located then run display messsage box
catch (Exception e1)
{
MessageBox.Show(e1.Message);
}


Thank you for reading. Any help would be very much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top