• 大小: 60KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-18
  • 语言: C#
  • 标签: C#  winform  combox  XML  

资源简介

C# winform实现combox绑定XML实现级联数据绑定

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.xml;

namespace xmlDemo2
{
public partial class Form1 : Form
{
xmlDocument doc = new xmlDocument();

public Form1()
{
InitializeComponent();



doc.Load(“省市区.xml“);


xmlNode provinces = doc.SelectSingleNode(“/ProvinceCity“);
foreach (xmlNode province in provinces.ChildNodes) {
cbxProvince.Items.Add(province.Name);
}
cbxProvince.SelectedIndex = 0;
}

private void cbxProvince_SelectedIndexChanged(object sender EventArgs e)
{
cbxCity.Items.Clear();

string xpath = string.Format(“/ProvinceCity/{0}/City“ cbxProvince.SelectedItem.ToString());
xmlNodeList cities = doc.SelectNodes(xpath);
foreach (xmlNode city in cities) {
cbxCity.Items.Add(city.Attributes[“Name“].Value);
}

if(cbxCity.Items.Count >= 0) {
cbxCity.SelectedIndex = 0;
}
}

private void cbxCity_SelectedIndexChanged(object sender EventArgs e)
{
cbxCityArea.Items.Clear();

string xpath = string.Format(“/ProvinceCity/{0}/City[@Name=‘{1}‘]/CityArea“ 
cbxProvince.SelectedItem.ToString()
cbxCity.SelectedItem.ToString());

xmlNodeList CityAreas = doc.SelectNodes(xpath);
foreach (xmlNode area in CityAreas) {
cbxCityArea.Items.Add(area.Attributes[“Name“].Value);
}

if(cbxCityArea.Items.Count > 0) {
cbxCityArea.SelectedIndex = 0;
}
}
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       9728  2016-02-20 13:17  xmlDemo2\xmlDemo2\xmlDemo2\bin\Debug\xmlDemo2.exe

     文件      26112  2016-02-20 13:17  xmlDemo2\xmlDemo2\xmlDemo2\bin\Debug\xmlDemo2.pdb

     文件      11608  2016-06-18 08:34  xmlDemo2\xmlDemo2\xmlDemo2\bin\Debug\xmlDemo2.vshost.exe

     文件        490  2010-03-17 22:39  xmlDemo2\xmlDemo2\xmlDemo2\bin\Debug\xmlDemo2.vshost.exe.manifest

     文件     116929  2013-06-09 14:46  xmlDemo2\xmlDemo2\xmlDemo2\bin\Debug\省市区.xml

     文件       1576  2013-06-09 15:10  xmlDemo2\xmlDemo2\xmlDemo2\Form1.cs

     文件       2630  2013-06-09 15:10  xmlDemo2\xmlDemo2\xmlDemo2\Form1.Designer.cs

     文件       5817  2013-06-09 15:10  xmlDemo2\xmlDemo2\xmlDemo2\Form1.resx

     文件       1229  2016-05-27 09:09  xmlDemo2\xmlDemo2\xmlDemo2\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       5289  2016-06-18 08:33  xmlDemo2\xmlDemo2\xmlDemo2\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       3472  2013-06-09 15:10  xmlDemo2\xmlDemo2\xmlDemo2\obj\x86\Debug\ResGen.read.1.tlog

     文件        772  2013-06-09 15:10  xmlDemo2\xmlDemo2\xmlDemo2\obj\x86\Debug\ResGen.write.1.tlog

     文件       1281  2016-06-18 08:34  xmlDemo2\xmlDemo2\xmlDemo2\obj\x86\Debug\xmlDemo2.csproj.FileListAbsolute.txt

     文件        902  2016-02-20 13:17  xmlDemo2\xmlDemo2\xmlDemo2\obj\x86\Debug\xmlDemo2.csproj.GenerateResource.Cache

     文件       9728  2016-02-20 13:17  xmlDemo2\xmlDemo2\xmlDemo2\obj\x86\Debug\xmlDemo2.exe

     文件        180  2016-02-20 13:17  xmlDemo2\xmlDemo2\xmlDemo2\obj\x86\Debug\xmlDemo2.Form1.resources

     文件      26112  2016-02-20 13:17  xmlDemo2\xmlDemo2\xmlDemo2\obj\x86\Debug\xmlDemo2.pdb

     文件        180  2016-02-20 13:17  xmlDemo2\xmlDemo2\xmlDemo2\obj\x86\Debug\xmlDemo2.Properties.Resources.resources

     文件        391  2013-06-09 14:50  xmlDemo2\xmlDemo2\xmlDemo2\Program.cs

     文件       1366  2013-06-09 14:50  xmlDemo2\xmlDemo2\xmlDemo2\Properties\AssemblyInfo.cs

     文件       2513  2013-06-09 14:50  xmlDemo2\xmlDemo2\xmlDemo2\Properties\Resources.Designer.cs

     文件       5612  2013-06-09 14:50  xmlDemo2\xmlDemo2\xmlDemo2\Properties\Resources.resx

     文件       1015  2013-06-09 14:50  xmlDemo2\xmlDemo2\xmlDemo2\Properties\Settings.Designer.cs

     文件        249  2013-06-09 14:50  xmlDemo2\xmlDemo2\xmlDemo2\Properties\Settings.settings

     文件       3423  2013-06-09 14:50  xmlDemo2\xmlDemo2\xmlDemo2\xmlDemo2.csproj

     文件        866  2013-06-09 14:50  xmlDemo2\xmlDemo2\xmlDemo2.sln

    ..A..H.     16384  2016-06-18 17:31  xmlDemo2\xmlDemo2\xmlDemo2.suo

     目录          0  2013-06-09 14:50  xmlDemo2\xmlDemo2\xmlDemo2\obj\x86\Debug\TempPE

     目录          0  2016-05-27 09:09  xmlDemo2\xmlDemo2\xmlDemo2\obj\x86\Debug

     目录          0  2013-06-09 14:51  xmlDemo2\xmlDemo2\xmlDemo2\bin\Debug

............此处省略10个文件信息

评论

共有 条评论