BF2Statistics.MapListForm.MapListSelect_SelectedIndexChanged C# (CSharp) Method

MapListSelect_SelectedIndexChanged() private method

Called when a map is selected or changed
private MapListSelect_SelectedIndexChanged ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        private void MapListSelect_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Reset image
            MapPictureBox.Image = null;

            // If an error occurs while loading the maps .desc file, then just return
            if (MapListSelect.SelectedIndex == -1)
                return;

            // Dont Need to reset anything if its the first time loading a map
            if (!isMapSelected)
            {
                GameModeSelect.Enabled = true;
                isMapSelected = true;
            }
            else
            {
                // Reset select list's text
                MapSizeSelect.Text = "";
                GameModeSelect.Text = "";

                // Remove all items from the Mode select and MapSize select
                GameModeSelect.Items.Clear();
                MapSizeSelect.Items.Clear();

                // Disable MapList select
                MapSizeSelect.Enabled = false;
                AddToMapList.Enabled = false;
            }

            // Try and load the map object... a common error here is that the
            // Descriptor file containing illegal XML characters
            try
            {
                string map = MapListSelect.SelectedItem.ToString();
                SelectedMap = MainForm.SelectedMod.LoadMap(map);
                isMapSelected = true;
            }
            catch (Exception E)
            {
                // Get our Inner exception message if its an InvalidMapException
                // We do this because InvalidMapException doesnt really tell us the issue,
                // but if there is an inner exception, we will have the issue.
                string mess = (E is InvalidMapException && E.InnerException != null)
                    ? E.InnerException.Message
                    : E.Message;
                MessageBox.Show("There was an error loading the map descriptor file"
                    + Environment.NewLine + Environment.NewLine
                    + "Message: " + mess,
                    "Map Loading Error", MessageBoxButtons.OK, MessageBoxIcon.Warning
                );

                // Reset the GUI
                MapListSelect.SelectedIndex = -1;
                GameModeSelect.Enabled = false;
                isMapSelected = false;
            }

            // If we have no map loaded, it failed
            if (!isMapSelected)
                return;

            // Add all map supported game modes to the GameMode select list
            foreach (KeyValuePair<string, List<string>> Mode in SelectedMap.GameModes)
                GameModeSelect.Items.Add(new KeyValuePair(Mode.Key, GameModeToString(Mode.Key)));

            // Set the default map gamemode
            GameModeSelect.SelectedIndex = 0;
        }