ARKBreedingStats.Form1.updateTreeListSpecies C# (CSharp) Метод

updateTreeListSpecies() приватный Метод

This function should be called if the creatureCollection is changed, i.e. after loading a file or adding/removing a creature. It updated the listed species in the treelist.
private updateTreeListSpecies ( List creatures ) : void
creatures List
Результат void
        private void updateTreeListSpecies(List<Creature> creatures)
        {
            string selectedSpecies = "";
            if (listBoxSpeciesLib.SelectedIndex >= 0)
                selectedSpecies = listBoxSpeciesLib.SelectedItem.ToString();
            // clear specieslist
            listBoxSpeciesLib.Items.Clear();
            // add node to show all
            listBoxSpeciesLib.Items.Add("All");

            foreach (Creature cr in creatures)
            {
                // add new item for species if not existent
                if (listBoxSpeciesLib.Items.IndexOf(cr.species) == -1)
                {
                    // add new node alphabetically
                    int nn = 0;
                    while (nn < listBoxSpeciesLib.Items.Count && String.Compare(listBoxSpeciesLib.Items[nn].ToString(), cr.species, true) < 0) { nn++; }
                    listBoxSpeciesLib.Items.Insert(nn, cr.species);
                }
            }
            if (selectedSpecies.Length > 0)
                listBoxSpeciesLib.SelectedIndex = listBoxSpeciesLib.Items.IndexOf(selectedSpecies);

            // set the same species to breedingplaner, except the 'all'
            selectedSpecies = "";
            if (listViewSpeciesBP.SelectedIndices.Count > 0)
                selectedSpecies = listViewSpeciesBP.SelectedIndices[0].ToString();
            listViewSpeciesBP.Items.Clear();

            ListViewItem lvi;
            for (int i = 1; i < listBoxSpeciesLib.Items.Count; i++)
            {
                lvi = new ListViewItem(listBoxSpeciesLib.Items[i].ToString());
                lvi.Tag = listBoxSpeciesLib.Items[i].ToString();
                // check if species has both available males and females
                if (creatures.Count(c => c.species == listBoxSpeciesLib.Items[i].ToString() && c.status == CreatureStatus.Available && c.gender == Gender.Female) > 0 && creatures.Count(c => c.species == listBoxSpeciesLib.Items[i].ToString() && c.status == CreatureStatus.Available && c.gender == Gender.Male) == 0)
                    lvi.ForeColor = Color.LightGray;
                listViewSpeciesBP.Items.Add(lvi);
            }

            // select previous selecteded again
            if (selectedSpecies.Length > 0)
            {
                for (int i = 0; i < listViewSpeciesBP.Items.Count; i++)
                {
                    if ((string)listViewSpeciesBP.Items[i].Tag == selectedSpecies)
                    {
                        listViewSpeciesBP.Items[i].Focused = true;
                        listViewSpeciesBP.Items[i].Selected = true;
                        break;
                    }
                }
            }
        }
Form1