//Select two items in the list and merge them, the outcome will be a child private void MergeButton_Click(object sender, EventArgs e) { //controls if more than one person is selected to merge or less than two if (PersonListBox.SelectedItems.Count >= 3 || PersonListBox.SelectedItems.Count < 2) { CustomMessageBox.ShowBox("Only two people make a baby!\n\nDo the maths.."); PersonListBox.ClearSelected(); } //controls so that different sexes can make a baby and not two men or two women if ((Person)PersonListBox.SelectedItems[0] == (Person)PersonListBox.SelectedItems[1]) { CustomMessageBox.ShowBox("You need a boy and a girl to\nmake babies!\n\nDidn't they teach you anything\nat school?"); PersonListBox.ClearSelected(); } //once two people are selected .... else if (PersonListBox.SelectedItems.Count == 2) { //checks with a method that the two selected people are adults if (m1.CheckInsest((Person)PersonListBox.SelectedItems[0], (Person)PersonListBox.SelectedItems[1])) { // No Merge! PersonListBox.ClearSelected(); } else { //uses a method to make a new baby(child) m1.MakeABaby((Person)PersonListBox.SelectedItems[0], (Person)PersonListBox.SelectedItems[1]); peopleList.Add(m1.NewBaby); CustomMessageBox.ShowBox("Hi-dilly-ho, neighborinhos!\n\nI've done everything the Bible says,\neven the stuff that contradicts \nthe other stuff.\n\nAnd now we're having a baby!"); } } UpdateListBox(); }
/// <summary> /// Live search is here! /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SearchTextBox_TextChanged(object sender, EventArgs e) { // known cevat: // cant remove people in the list while searching. PersonListBox.DataSource = new BindingList <Person>(peopleList.Where(m => m.ToString().ToLower().Contains(SearchTextBox.Text.ToLower())).ToList()); PersonListBox.ClearSelected(); UpdateListBox(); }
//method to update the listBox private void UpdateListBox() { //Currency Manager used to keep the data from the listbox and the List synchronised ((CurrencyManager)PersonListBox.BindingContext[peopleList]).Refresh(); PersonListBox.ClearSelected(); }