Ejemplo n.º 1
0
        private void FillAssgnCheckedListBox(IEnumerable <string> activeCats)
        {
            List <string> prevUnchecked = new List <string>();
            List <string> prevExisted   = new List <string>();

            foreach (var item in CheckedListBoxAssignments.Items)
            {
                prevExisted.Add(item.ToString());
                if (!CheckedListBoxAssignments.CheckedItems.Contains(item))
                {
                    prevUnchecked.Add(item.ToString());
                }
            }
            CheckedListBoxAssignments.Items.Clear();

            List <string> assgnsInCats = new List <string>();

            foreach (var item in activeCats)
            {
                int          index      = _schoolClass.CatExists(item);
                Assignment[] tempAssgns = _schoolClass.GetAssgnsInCat(index);
                foreach (Assignment assgn in tempAssgns)
                {
                    assgnsInCats.Add(assgn.name);
                }
            }
            foreach (string assgnName in assgnsInCats)
            {
                CheckedListBoxAssignments.Items.Add(assgnName);
                if (prevExisted.Contains(assgnName))
                {
                    CheckedListBoxAssignments.SetItemChecked(CheckedListBoxAssignments.Items.IndexOf(assgnName),
                                                             !prevUnchecked.Contains(assgnName));
                }
                else
                {
                    CheckedListBoxAssignments.SetItemChecked(CheckedListBoxAssignments.Items.IndexOf(assgnName), true);
                }
            }
        }