EDN Admin
Well-known member
First off, Im quite new to C# and programming in general. Second, thank you very much in advance for helpful advice.
I have a Treeview that uses a sortedlist of an xml files data to populate it. Now loading it, is easy enough
<div style="color:Black;background-color:White; <pre>
XmlDocument doc = <span style="color:Blue; new XmlDocument();
doc.Load(<span style="color:#A31515; "Subscription.xml");
XmlElement root = doc.DocumentElement;
XmlNodeList subNodes = root.SelectNodes(<span style="color:#A31515; "//SUB");
list = <span style="color:Blue; new SortedList<<span style="color:Blue; string, <span style="color:Blue; string>();
<span style="color:Blue; foreach (XmlNode sub <span style="color:Blue; in subNodes)
{
<span style="color:Blue; string name = sub[<span style="color:#A31515; "Name"].InnerText;
<span style="color:Blue; string url = sub[<span style="color:#A31515; "Url"].InnerText;
list.Add(name, url);
}
<span style="color:Blue; foreach (KeyValuePair<<span style="color:Blue; string, <span style="color:Blue; string> kvp <span style="color:Blue; in list)
{
<span style="color:Blue; string name = kvp.Key;
<span style="color:Blue; string url = kvp.Value;
<span style="color:Green; //MessageBox.Show(name + " => " + url);
treeSidebar.Nodes[0].Nodes.Add(name);
}
treeSidebar.ExpandAll();
treeSidebar.SelectedNode = treeSidebar.Nodes[0];
[/code]
But when I add a new node to the treeview, Im editing the xml file the treeview uses for storage/loading. When I close the child form that I use to edit/alter the xml file this event happens:
<div style="color:Black;background-color:White; <pre>
NewSubscription frmNewSub = <span style="color:Blue; new NewSubscription();
<span style="color:Blue; if (frmNewSub.SubscriptionTextBox.Text != <span style="color:Blue; null)
{
MessageBox.Show(frmNewSub.SubscriptionTextBox.Text);
treeSidebar.Nodes.Remove(treeSidebar.Nodes[0]);
doc.Load(<span style="color:#A31515; "Subscription.xml");
XmlElement root = doc.DocumentElement;
XmlNodeList subNodes = root.SelectNodes(<span style="color:#A31515; "//SUB");
list = <span style="color:Blue; new SortedList<<span style="color:Blue; string, <span style="color:Blue; string>();
<span style="color:Blue; foreach (XmlNode sub <span style="color:Blue; in subNodes)
{
<span style="color:Blue; string name = sub[<span style="color:#A31515; "Name"].InnerText;
<span style="color:Blue; string url = sub[<span style="color:#A31515; "Url"].InnerText;
list.Add(name, url);
}
<span style="color:Blue; foreach (KeyValuePair<<span style="color:Blue; string, <span style="color:Blue; string> kvp <span style="color:Blue; in list)
{
<span style="color:Blue; string name = kvp.Key;
<span style="color:Blue; string url = kvp.Value;
<span style="color:Green; //MessageBox.Show(name + " => " + url);
treeSidebar.Nodes[0].Nodes.Add(name);
}
treeSidebar.ExpandAll();
treeSidebar.SelectedNode = treeSidebar.Nodes[0];
}
[/code]
Well, its supposed to happen a different way than it is. All it does is clear the treeview and then shoots down to the selected node part of the code. Currently, it is telling me it cant load the xml file because another process is using it. So my question,
I guess, is how do I close the xml file after the treeview has loaded it, so I can access it in my second code? Sorry if this is a novice or moronic question, once again Im very new to C# and programming in general.<br/>
<br/>
View the full article
I have a Treeview that uses a sortedlist of an xml files data to populate it. Now loading it, is easy enough
<div style="color:Black;background-color:White; <pre>
XmlDocument doc = <span style="color:Blue; new XmlDocument();
doc.Load(<span style="color:#A31515; "Subscription.xml");
XmlElement root = doc.DocumentElement;
XmlNodeList subNodes = root.SelectNodes(<span style="color:#A31515; "//SUB");
list = <span style="color:Blue; new SortedList<<span style="color:Blue; string, <span style="color:Blue; string>();
<span style="color:Blue; foreach (XmlNode sub <span style="color:Blue; in subNodes)
{
<span style="color:Blue; string name = sub[<span style="color:#A31515; "Name"].InnerText;
<span style="color:Blue; string url = sub[<span style="color:#A31515; "Url"].InnerText;
list.Add(name, url);
}
<span style="color:Blue; foreach (KeyValuePair<<span style="color:Blue; string, <span style="color:Blue; string> kvp <span style="color:Blue; in list)
{
<span style="color:Blue; string name = kvp.Key;
<span style="color:Blue; string url = kvp.Value;
<span style="color:Green; //MessageBox.Show(name + " => " + url);
treeSidebar.Nodes[0].Nodes.Add(name);
}
treeSidebar.ExpandAll();
treeSidebar.SelectedNode = treeSidebar.Nodes[0];
[/code]
But when I add a new node to the treeview, Im editing the xml file the treeview uses for storage/loading. When I close the child form that I use to edit/alter the xml file this event happens:
<div style="color:Black;background-color:White; <pre>
NewSubscription frmNewSub = <span style="color:Blue; new NewSubscription();
<span style="color:Blue; if (frmNewSub.SubscriptionTextBox.Text != <span style="color:Blue; null)
{
MessageBox.Show(frmNewSub.SubscriptionTextBox.Text);
treeSidebar.Nodes.Remove(treeSidebar.Nodes[0]);
doc.Load(<span style="color:#A31515; "Subscription.xml");
XmlElement root = doc.DocumentElement;
XmlNodeList subNodes = root.SelectNodes(<span style="color:#A31515; "//SUB");
list = <span style="color:Blue; new SortedList<<span style="color:Blue; string, <span style="color:Blue; string>();
<span style="color:Blue; foreach (XmlNode sub <span style="color:Blue; in subNodes)
{
<span style="color:Blue; string name = sub[<span style="color:#A31515; "Name"].InnerText;
<span style="color:Blue; string url = sub[<span style="color:#A31515; "Url"].InnerText;
list.Add(name, url);
}
<span style="color:Blue; foreach (KeyValuePair<<span style="color:Blue; string, <span style="color:Blue; string> kvp <span style="color:Blue; in list)
{
<span style="color:Blue; string name = kvp.Key;
<span style="color:Blue; string url = kvp.Value;
<span style="color:Green; //MessageBox.Show(name + " => " + url);
treeSidebar.Nodes[0].Nodes.Add(name);
}
treeSidebar.ExpandAll();
treeSidebar.SelectedNode = treeSidebar.Nodes[0];
}
[/code]
Well, its supposed to happen a different way than it is. All it does is clear the treeview and then shoots down to the selected node part of the code. Currently, it is telling me it cant load the xml file because another process is using it. So my question,
I guess, is how do I close the xml file after the treeview has loaded it, so I can access it in my second code? Sorry if this is a novice or moronic question, once again Im very new to C# and programming in general.<br/>
<br/>
View the full article