0

我在这些链接上找到了最接近我的问题的参考:

ComboBox 在 Clear() 之后有它的旧值
为什么只有在 ListItem 的索引更改后才会触发选定的索引?

我有 4 个组合框:cmbcountrycmbstate和. 按方法填充加载事件。按方法填充,该方法将's selectedvalue 作为参数并返回相关状态的列表,依此类推 for and ... cmbdistrictcmbcitycmbcountryGetCountry()cmbstateGetState(countryid)cmbcountrycmbdistrictcmbcity

问题在于在 中选择不同的项目cmbStatecmbDistrct没有填充正确的项目。

.例如状态:“中央邦”,“外邦”,“拉杰斯坦”

对于“Rajsthan”,cmbdistrict 填充了相关值,但对于“Utter pradesh”,cmbdistrict 仍然具有旧值。

以下是相关代码:

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() 会出错。

请告诉我是否还有其他我遗漏的相关参考资料。

4

0 回答 0