我想问我如何让combobox显示我添加的xml文件的值又为可以为他添加value。
在线等,本人新手,不知道说的明不明白,望牛人指教指教啊,非常感谢。
XML文件的结构为1.{ a.
b.
c.}
2.{ 1.
2.
3.} 添加两个combobox,第一个输出1. 2.。第二个根据第一个cmobobox输入的值相应的显示出来。 现在要为两个combobox添加value,我用数据绑定的办法,就是建立一个arraylist,具体方法是
ArrayList arList=new ArrayList();
arList.Add(new DictionaryEntry("1", "China"));
arList.Add(new DictionaryEntry("2", "England"));
arList.Add(new DictionaryEntry("3", "USA"));
this.comboBox1.DisplayMember = "Value";
this.comboBox1.ValueMember = "Key";
this.comboBox1.DataSource = arList
现在有个问题,这样绑定的话。cmobobox中显示的是我建立的数据源的名称,把displaymember程序行去掉还是有问题。
在线等,本人新手,不知道说的明不明白,望牛人指教指教啊,非常感谢。
XML文件的结构为1.{ a.
b.
c.}
2.{ 1.
2.
3.} 添加两个combobox,第一个输出1. 2.。第二个根据第一个cmobobox输入的值相应的显示出来。 现在要为两个combobox添加value,我用数据绑定的办法,就是建立一个arraylist,具体方法是
ArrayList arList=new ArrayList();
arList.Add(new DictionaryEntry("1", "China"));
arList.Add(new DictionaryEntry("2", "England"));
arList.Add(new DictionaryEntry("3", "USA"));
this.comboBox1.DisplayMember = "Value";
this.comboBox1.ValueMember = "Key";
this.comboBox1.DataSource = arList
现在有个问题,这样绑定的话。cmobobox中显示的是我建立的数据源的名称,把displaymember程序行去掉还是有问题。
解决方案 »
- 关于线程加锁的一个奇怪问题
- 请问高手一个c#问题
- 一个textBox,一个listbox现在listbox里面的数据是通过数组得出的,问题要通过textbox筛选到唯一的一个在listbox里面的数据
- 一条SQL语句
- 如何知道ListViewBox当前选择了哪一个单元格?
- 求水晶报表的教程,谢谢了,基础一点为好
- 关于vs2005开发wince5.0
- List绑定到DGV的简单问题 ,求帮忙
- 请问sql server2000中的数据类型与c#中的数据类型一一对应问题!
- 关于c#调用 windows api 的问题 高手请进 造福菜鸟
- 怎么让Comobox的每个Item显示ToolTip
- 得到listview选中行数
public void InsertCombobox(ComboBox comb, string node)
{
XmlDocument document = new XmlDocument();
document.Load(path);//xml文件的路径。
XmlElement root = document.DocumentElement;
XmlNodeList nodelist = root.SelectNodes(node);
foreach (XmlNode nodes in nodelist)
comb.Items.Add(nodes.InnerText);
} private void Form1_Load(object sender, EventArgs e) XML读入第一个combobox
{ string node = "//CheckName/title";
InsertCombobox(comboBox1, node); }
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e) 根据第一个combobox选择的项目,使第二个combobox显示对应的值
{
comboBox2.Items.Clear();
string chosen = comboBox1.Text;
switch (chosen.ToString())
{
case "1.":
string nodeasus = "//CheckName[title='1.']/checknodename/checknode";
InsertCombobox(comboBox2, nodeasus);
break;
case "2.":
string nodeacer = "//CheckName[title='2.']/checknodename/checknode";
InsertCombobox(comboBox2, nodeacer);
break;
}
-<Checkall>
- <CheckName>
<title>1.</title>
- <checknodename>
<checknode>abcd</checknode>
</checknodename>
</CheckName>
- <CheckName>
<title>2.</title>
- <checknodename>
<checknode>bcde</checknode>
</checknodename>
</CheckName>
</CheckAll> 这样再使用上面的数据绑定就会出现问题。