调换下赋值的顺序就会报错!
private DataSet ds = new DataSet(); private void getProvinceAndCity() { GetPriceInfo_BLL bll = new GetPriceInfo_BLL(); ds = bll.GetPriceInfoFromJsw_Bll(); comPriceInfoProvince.DisplayMember = "province_name"; comPriceInfoProvince.ValueMember = "province_id"; comPriceInfoProvince.DataSource = ds.Tables["Province"]; comPriceInfoProvince.SelectedIndex = 0; }
//Get city according by province. private void comPriceInfoProvince_SelectedIndexChanged(object sender, EventArgs e) { if (comPriceInfoCity.Items.Count > 0) { comPriceInfoCity.DataSource = new DataTable(); } int province_id = int.Parse(comPriceInfoProvince.SelectedValue.ToString()); GetPriceInfo_BLL bll = new GetPriceInfo_BLL(); DataTable dtOfCitys = bll.GetCitysByProvinceFromJsw_Dal(province_id); comPriceInfoCity.DataSource = dtOfCitys; comPriceInfoCity.DisplayMember = "city_name"; comPriceInfoCity.ValueMember = "city_id"; comPriceInfoCity.SelectedIndex = 0; }