本文介绍了如何在带有I / O XMLfile的程序中使用comboBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个XML文件,其结构如下,希望将某些节点的值添加到组合框中,具体取决于条件。因此,组合框的数量是可变的,最大数量是25.我如何设置组合框或命名它们? XML文件结构: < 数据集 > < r > < C1 > v1 < / C1 > < C2 > v2 < / C2 > < C 3 > v3 < / C3 > < / r > < r > < C1 > v11 < / C1 > < C2 > v22 < / C2 > < C3 > v33 < / C3 > < / r > 。 。 。 < / DataSet > 一种方法是我们首先创建25个组合框并隐藏它们,但我不知道如何对它们进行namming或初始化? a部分代码: XmlDocument xmlDoc = new XmlDocument() ; xmlDoc.Load(inputXml); XmlNode root = xmlDoc.DocumentElement; XmlNodeList节点= root.ChildNodes; for ( int i = 0 ; i < (nodes.Count) - 1 ; i ++) if (nodes [i] .ChildNodes [ 0 ]。InnerText == sidtextbox .Text) { create comboBox [k]或者显示comboBox [k]; /// ///如何做namming ...... ????? comboBox [k] .Items.Add(nodes [i] .ChildNodes [ 2 ]。InnerText); /// ///如何... ????? } 解决方案 尝试这样的事情.. 创建一个占位符,即 TableLayoutPanel 。 在代码方面,像这样迭代你的XML ComboBox cmbx; for ( int i = 0 ; i < 4 ; i ++) { cmbx = new ComboBox(); cmbx.Name = string .Format( MyCmb_ {0},i.ToString()); cmbx.DataSource = new string [] { Zubair, Ali }; // 此行将在每个下拉菜单中添加两个来源Zubair,Ali。 // cmbx.DataSource =您的数据源需要在此处添加。 tableLayoutPanel1.Controls.Add(cmbx); } 使用上述样本。为您设置 TableLayoutPanel 。动态给出组合框名称并在循环中分配每个组合框,其中循环将迭代 XMLDocument 节点数。 有关TableLayoutPanel的更多详细信息,您可以访问 Link [ ^ ] Hi,I have a XMLfile with following structure that want to add value of some nodes to comboBoxes Depending on if conditions. Therefore the number of comboBoxes is variable and maximum number is 25. how do i set comboBoxes or namming them?XMLfile structure:<Dataset> <r> <C1>v1</C1> <C2>v2</C2> <C3>v3</C3> </r> <r> <C1>v11</C1> <C2>v22</C2> <C3>v33</C3> </r>...</DataSet>One way is that we create 25 comboBoxes and hide them at first, but i don't know how to doing namming or initialize them together?a part of my code:XmlDocument xmlDoc = new XmlDocument();xmlDoc.Load(inputXml);XmlNode root = xmlDoc.DocumentElement;XmlNodeList nodes = root.ChildNodes;for (int i = 0; i < (nodes.Count) - 1; i++)if (nodes[i].ChildNodes[0].InnerText == sidtextbox.Text) { create comboBox[k] OR showing comboBox[k]; //////How to doing namming ...????? comboBox[k].Items.Add(nodes[i].ChildNodes[2].InnerText); //////How to ...????? } 解决方案 Try something like this..Create a placeholder, i.e. TableLayoutPanel.In code side, iterate on your XML like thisComboBox cmbx; for (int i = 0; i < 4; i++) { cmbx = new ComboBox(); cmbx.Name = string.Format("MyCmb_{0}", i.ToString()); cmbx.DataSource = new string[]{"Zubair", "Ali"}; //This line will add two sources Zubair, Ali in each of dropdown. //cmbx.DataSource = Your data source need to be added here. tableLayoutPanel1.Controls.Add(cmbx); }Use above mentioned sample. Setup TableLayoutPanel for you. give comboBoxes names dynamically and assign each of combobox inside your loop where loop will iterate on your XMLDocument nodes count.For further details on TableLayoutPanel, you can go though following Link[^] 这篇关于如何在带有I / O XMLfile的程序中使用comboBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-31 16:35