0
我有一個xml填充組合框。如果builderemail(使用streamreader解析文本)等於xml文件中找到的任何一個值,組合框將選擇索引。我如何選擇它?我如何選擇節點的索引?
if (line.StartsWith("Builder_Email:"))
{
bool IsNodeExists = false;
string[] fields = line.Split('\t');
string builderemail = fields[3];
XmlDocument emailparse = new XmlDocument();
emailparse.Load(@"C:\GUI\buildermanageremail.xml");
XmlNodeList emailnode = emailparse.GetElementsByTagName("value");
if (string.IsNullOrEmpty(builderemail))
comboBox1.SelectedIndex = -1;
else
foreach (XmlNode node in emailnode)
{
if (builderemail == node.InnerText)
{
// how do i get the combobox selection right?
// need some code here
IsNodeExists = true;
break;
}
}
if(!IsNodeExists)
{
//create main node
XmlNode abc = emailparse.CreateNode(XmlNodeType.Element, "builder", null);
//create the first child node
XmlNode value = emailparse.CreateElement("value");
//set the value
value.InnerText = builderemail;
// add childes to father
//node.AppendChild(id);
abc.AppendChild(value);
// find the node we want to add the new node to
XmlNodeList l = emailparse.GetElementsByTagName("builderemail");
// append the new node
l[0].AppendChild(abc);
// save the file
emailparse.Save(@"C:\GUI\buildermanageremail.xml");
//then we populate the new updated xml file into the drop down list:
PopulateDDLFromXMLFile();
int count = emailparse.SelectNodes("email/builderemail/builder").Count;
count--;
comboBox1.SelectedIndex = count;
}
}
看的地方是在這裏:
foreach (XmlNode node in emailnode)
{
if (builderemail == node.InnerText)
{
// how do i get the combobox selection right?
// need some code here
IsNodeExists = true;
break;
}
}
你說的'正確index'意思,什麼是'someinteger' – 2011-03-21 07:54:17
someinteger指的是價值,無論是如果一個節點計數或東西 – jeremychan 2011-03-21 07:56:08
你能不能改一下你的問題到底在簡單來說,我不能」不明白什麼**正確的索引**意味着,可能你已經獲得了正確的索引。 – 2011-03-21 07:57:15