I have a datagridview where I want to get a list of persons build on the values of the checkboxes (ID's saved in the tag of the checkbox). Those checkboxes are build by code and added to 2 different groupboxes (sgbExcursion and sgbLanguage)
The filter works fine if you select just one excursion (upper checkboxes) and just one language.
If I select 2 languages (lower checkboxes) it is treaten as "or". All persons speaking one of the selected languages are shown instead of only persons who speak both of the selected languages. Same problem with the excursions.
Here I build the list of selected excursions and languages:
List<int> oExcursionID = new List<int>();
foreach (Control oControl in sgbExcursion.Controls)
{
if (oControl.GetType() == typeof(CheckBox))
{
CheckBox oCheckBox = (CheckBox)oControl;
if (oCheckBox.Checked)
{
oExcursionID.Add(int.Parse(oCheckBox.Tag.ToString()));
}
}
}
List<int> oLanguageID = new List<int>();
foreach (Control oControl in sgbLanguage.Controls)
{
if (oControl.GetType() == typeof(CheckBox))
{
CheckBox oCheckBox = (CheckBox)oControl;
if (oCheckBox.Checked)
{
oLanguageID.Add(int.Parse(oCheckBox.Tag.ToString()));
}
}
}
Here I try to get the right values out of the database. Both languages and excursions are saved in a relational table (Person_ID, Exursion_ID) or (Person_ID, Language_ID).
var vGuides = (from oGuideToAdd in clsApplication._oDBConnection.tblGuides
where ((from oGuideExcursion in clsApplication._oDBConnection.tblGuideExcursions
where oExcursionID.Contains(oGuideExcursion.ExcursionID)
select oGuideExcursion.GuideID).Contains(oGuideToAdd.ID)
&& (from oGuideLanguage in clsApplication._oDBConnection.tblGuideLanguages
where oLanguageID.Contains(oGuideLanguage.LanguageID)
select oGuideLanguage.GuideID).Contains(oGuideToAdd.ID))
select oGuideToAdd).ToList();
What can I change to get the right output?