如何调试我的国家>陈述>城市代码,以便显示州和城市?

时间:2018-02-28 23:19:14

标签: c# .net

private void Form2_Load(object sender, EventArgs e)
{
    var countries = from country in xdoc.Descendants("countries").Elements("country").Attributes("name")
                    select country.Value;
    comboBox_country.DataSource = countries.ToList()
}

private void comboBox_country_SelectedIndexChanged(object sender, EventArgs e)
{
    var states = from country in xdoc.Descendants("countries").Elements("country")
                 where country.Attribute("name").Value == comboBox_country.SelectedValue
                 select country;

    var s = from state in states.Elements("state")
            select state.Value;
    comboBox_state.DataSource = s.ToList();
}

private void comboBox_state_SelectedIndexChanged(object sender, EventArgs e)
{
    var cities = from state in xdoc.Descendants("state").Elements("state")
                 where state.Attribute("name").Value == comboBox_state.SelectedValue
                 select state;

    var c = from city in cities.Elements("city")
            select city.Value;
           comboBox_city.DataSource = c.ToList();
}

我需要在哪里进行修改?

我正在尝试选择与州和相关城市相关的国家/地区。我已经创建了一个XML文件,并尝试从该XML文件读取到一个win表格布局,该布局将国家/地区城市作为标签和相应的组合框。

0 个答案:

没有答案