我在这些链接上找到了最接近我的问题的参考:
我有 4 个组合框:cmbcountry
、cmbstate
和. 按方法填充加载事件。按方法填充,该方法将's selectedvalue 作为参数并返回相关状态的列表,依此类推 for and ...
cmbdistrict
cmbcity
cmbcountry
GetCountry()
cmbstate
GetState(countryid)
cmbcountry
cmbdistrict
cmbcity
问题在于在 中选择不同的项目cmbState
,cmbDistrct
没有填充正确的项目。
以下是相关代码:
private void TestForm1_Load(object sender, EventArgs e)
{
cmbCountry.ItemSource = Lookups.Lookup.GetCountries();
}
private void cmbCountry_SelectionChangeCommitted(object sender, EventArgs e)
{
cmbState.Text = "";
cmbState.Clear();
cmbState.SelectedIndex = -1;
cmbState.SelectedItem = null;
//cmbState.Items.Clear();
int countryId = Convert.ToInt32(cmbCountry.SelectedValue);
cmbState.ItemSource = Lookups.Lookup.GetStates(countryId);
}
private void cmbState_SelectionChangeCommitted(object sender, EventArgs e)
{
cmbDistrict.Text = "";
cmbDistrict.Clear();
cmbDistrict.SelectedIndex = -1;
cmbDistrict.SelectedItem = null;
//cmbDistrict.Items.Clear();
int stateId = Convert.ToInt32(cmbState.SelectedValue);
cmbDistrict.ItemSource = Lookups.Lookup.GetDistricts(stateId);
}
private void cmbDistrict_SelectionChangeCommitted(object sender, EventArgs e)
{
cmbCity.Text = "";
cmbCity.Clear();
cmbCity.SelectedIndex = -1;
cmbCity.SelectedItem = null;
//cmbCity.Items.Clear();
int DistrictId = Convert.ToInt32(cmbDistrict.SelectedValue);
cmbCity.ItemSource = Lookups.Lookup.GetCities(DistrictId);
}
private void cmbBank_SelectionChangeCommitted(object sender, EventArgs e)
{
int bankId = Convert.ToInt32(cmbBank.SelectedValue);
cmbControlBranch.ItemSource = Lookups.Lookup.GetBranches(bankId);
}
我有上述所有方法来清除组合框中的先前数据......如果我使用它,items.clear() 会出错。
请告诉我是否还有其他我遗漏的相关参考资料。