Hi i have a C# windows form that has two list boxes on it.The left one contains a list of 16 student module codes that are available to enrol onto. The user selects a module from the left to transfer to the right box. I have it working up to this point, the module code transfers when the select button is clicked.
Once a module has been transferred i need to click on it and print out onto a label (placed to the right of it)the full module details that are held in an XML file.
I am able to read through the contents of the XML file and output that to the label (all contents) what i need it to do is just print out the "SELECTED module" details to the label. So i have to somehow read through the XML file and pick out the particular module/modules that the user selects? So if he/she selects 8 modules then i just want the details of all of those to display on the label?
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 ModuleSelector.Entities;
using System.Xml;
using System.IO;
using System.Xml.XPath;
namespace ModuleSelector
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
String mName, mCode, mDescription, mCapacity, mLectureSlot, mTutorialSlot;
string workingDir = Directory.GetCurrentDirectory();
private void FormMain_Load(object sender, EventArgs e)
{
int slot = (int)Timetable.timeSlots.Monday4_6;
System.Console.WriteLine(slot);
}
private void listBoxModules_DragLeave(object sender, EventArgs e)
{
String module = (String)listBoxModules.SelectedItem;
}
private void listBoxModules_DrawItem(object sender, EventArgs e)
{
String module = (String)listBoxModules.SelectedItem;
}
private void buttonAddModule_Click(object sender, EventArgs e)
{
listBoxSelectedModules.Items.Add(listBoxModules.SelectedItem);
}
private void listBoxSelectedModules_DrawItem(object sender, DrawItemEventArgs e)
{
String module = (String)listBoxModules.SelectedItem;
}
private void listBoxModules_DrawItem(object sender, DrawItemEventArgs e)
{
String module = (String)listBoxModules.SelectedItem;
}
private void buttonRemoveModule_Click(object sender, EventArgs e)
{
listBoxSelectedModules.Items.Remove(listBoxModules.SelectedItem);
}
private void buttonSubmit_Click(object sender, EventArgs e)
{
}
private void listBoxSelectedModules_SelectedIndexChanged(object sender, EventArgs e)
{
XmlTextReader textReader = new XmlTextReader(workingDir + @"\XMLModules.xml");
while (textReader.Read())
{
textReader.MoveToElement();
//gets module name from XML file
if (textReader.Name == "moduleName")
{
textReader.Read();
XmlNodeType nType = textReader.NodeType;
if (nType == XmlNodeType.Text)
{
mName += (" Module Name: " + textReader.Value.ToString());
}
}
//gets module code from XML file
if (textReader.Name == "moduleCode")
{
textReader.Read();
XmlNodeType nType = textReader.NodeType;
if (nType == XmlNodeType.Text)
{
mCode += (" Module Code: " + textReader.Value.ToString());
}
}
//gets module description from XML file
if (textReader.Name == "moduleDescription")
{
textReader.Read();
XmlNodeType nType = textReader.NodeType;
if (nType == XmlNodeType.Text)
{
mDescription += (" Module Description: " +textReader.Value.ToString());
}
}
//Gets module capacity from XML file
if (textReader.Name == "moduleCapacity")
{
textReader.Read();
XmlNodeType nType = textReader.NodeType;
if (nType == XmlNodeType.Text)
{
mCapacity += (" Module Capacity: " + textReader.Value.ToString());
}
}
//Gets module Lecture slot from XML file
if (textReader.Name == "lectureSlot")
{
textReader.Read();
XmlNodeType nType = textReader.NodeType;
if (nType == XmlNodeType.Text)
{
mLectureSlot += (" Lecture Slot: " + textReader.Value.ToString());
}
}
//Gets tutorial slot from XML file
if (textReader.Name == "tutorialSlot")
{
textReader.Read();
XmlNodeType nType = textReader.NodeType;
if (nType == XmlNodeType.Text)
{
mTutorialSlot += (" Tutorial Slot: "+textReader.Value.ToString());
}
}
//Writes the data to the label
this.formLabel.Text = mName +
"\n" + mCode +
"\n" + mDescription +
"\n" + mCapacity +
"\n" + mLectureSlot +
"\n" + mTutorialSlot;
}
textReader.Close();
}
}
}
/**
module><moduleCode>3SFE504</moduleCode>
<moduleName>Algorithms and Data Structures</moduleName>
<moduleCapacity>5</moduleCapacity>
<semester>1</semester>
<Prerequisite>none</Prerequisite>
<lectureSlot>0</lectureSlot>
<tutorialSlot>1</tutorialSlot>
<moduleDescription>Data structures, ADT's and implementations</moduleDescription>
**/