读取xml文件加载到combox中
XmlDocument doc = new XmlDocument();
/// <summary>/// 省市级联
/// </summary>
private void init()
{
doc.Load(Command.GetApplicationPath()+"省市区.xml");
XmlNode provinces = doc.SelectSingleNode("/ProvinceCity");
foreach (XmlNode province in provinces.ChildNodes)
{
tscboxPro.Items.Add(province.Name);
}
tscboxPro.SelectedIndex = 0;
}
private void tscboxPro_SelectedIndexChanged(object sender, EventArgs e)
{
tscboxCity.Items.Clear();
string xpath = string.Format("/ProvinceCity/{0}/City", tscboxPro.SelectedItem.ToString());
XmlNodeList cities = doc.SelectNodes(xpath);
foreach (XmlNode city in cities)
{
tscboxCity.Items.Add(city.Attributes["Name"].Value);
}
if (tscboxCity.Items.Count >= 0)
{
tscboxCity.SelectedIndex = 0;
}
}
private void tscboxCity_SelectedIndexChanged(object sender, EventArgs e)
{
cbxCityArea.Items.Clear();
string xpath = string.Format("/ProvinceCity/{0}/City[@Name='{1}']/CityArea",
tscboxPro.SelectedItem.ToString(),
tscboxCity.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;
}
}
3817

被折叠的 条评论
为什么被折叠?



