我有一组字符串数组,我想与选中列表框的项目进行比较。我有两个选中列表框。第一个有三个框 idari(管理)、tumu(全部)和 teknik(技术)。第二个选中列表框包含所有名称(包括管理人员和技术人员)。我只希望在检查 idari 时检查 idari 字符串数组中的名称。teknik 和 tumu 也是如此。这是我的代码,但它只是继续检查我检查 idari 时的所有项目。谁能告诉我我的代码有什么问题?另外我在调用 chklstbox_bolum 方法时遇到问题。
string[] tumu = { "Jane", "Tom", "Danny", "John", "Jacyln", "Lily", "Lale" };
string[] idari = { "Jane", "Tom", "Danny" };
string[] teknik = { "John", "Jacyln", "Lily", "Lale"};
private void idari_secimi()
{ //function
if (chklstbx_bolum.GetItemChecked(1) == false)//if the idari check box has been checked in the checked list box
{
for (int i = 0; i < chklstbx_sonuc.Items.Count; i++){
for (int j = 0; j < idari.Length; j++)
{
if (chklstbx_sonuc.SelectedItem.ToString()==idari[j])
{
chklstbx_sonuc.SetItemChecked(i, true);
}
else { }
}
}
}
else if (chklstbx_bolum.GetItemChecked(1) == true)
{//unchecks all the items in the second checked list box when unchecking idari in the first checked list box.
for (int i = 0; i < chklstbx_sonuc.Items.Count; i++)
{
chklstbx_sonuc.SetItemChecked(i, false);
}
}
}
private void chklstbx_bolum_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (chklstbx_bolum.GetItemChecked(2) == false)
tumu_secimi();
//if the tumu box is checked call this function
else if (chklstbx_bolum.GetItemChecked(1) == false)
idari_secimi();
//if the idari box is checked call this function
else if (chklstbx_bolum.GetItemChecked(0) == false)
teknik_secimi();
//if the teknik box is checked call this function
}