private void searchTextBox_TextChanged(object sender, EventArgs e) { string searchTerm = searchTextBox.Text; if (string.IsNullOrWhiteSpace(searchTerm)) { backButton.Enabled = false; refreshMainForm(); clearSearchResults(); searchBoxLabel.Text = "Search Country:"; } else { backButton.Enabled = true; clearAllInput(); foreach (Country country in mainTree.GetCountries()) { if (country.Name.ToLower().StartsWith(searchTerm.ToLower().Trim())) { resultsTree.InsertItem(country); } } foreach (Country result in resultsTree.GetCountries()) { if (!result.Name.ToLower().StartsWith(searchTerm.ToLower().Trim())) { resultsTree.RemoveItem(result); } } countryList.DataSource = resultsTree.GetCountries(); countryList.DisplayMember = "name"; searchBoxLabel.Text = "Search Results: " + resultsTree.Count(); } }
private void deleteMenuItem_Click(object sender, EventArgs e) { if (MessageBox.Show("Do you want to remove " + selectedCountry.Name + " from the Main Tree?", "Delete Selected Country", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { mainTree.RemoveItem(selectedCountry); refreshMainForm(); } }