Fix pokelist reload error & fix button not working

Brian [2016-08-18 16:15:50]
Fix pokelist reload error & fix button not working
Filename
PokemonGo.RocketBot.Window/Forms/MainForm.cs
PokemonGo.RocketBot.Window/Forms/MainForm.designer.cs
PokemonGo.RocketBot.Window/Forms/SettingsForm.cs
diff --git a/PokemonGo.RocketBot.Window/Forms/MainForm.cs b/PokemonGo.RocketBot.Window/Forms/MainForm.cs
index b583fa1..7bea677 100644
--- a/PokemonGo.RocketBot.Window/Forms/MainForm.cs
+++ b/PokemonGo.RocketBot.Window/Forms/MainForm.cs
@@ -424,7 +424,7 @@ namespace PokemonGo.RocketBot.Window.Forms

         #endregion INTERFACE

-        #region BUTTONS
+        #region EVENTS

         private void btnRefresh_Click(object sender, EventArgs e)
         {
@@ -443,7 +443,12 @@ namespace PokemonGo.RocketBot.Window.Forms
             settingsForm.ShowDialog();
         }

-        #endregion BUTTONS
+        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
+        {
+            Environment.Exit(0);
+        }
+
+        #endregion EVENTS

         #region POKEMON LIST

@@ -469,10 +474,10 @@ namespace PokemonGo.RocketBot.Window.Forms
             olvPokemonList.FormatRow += delegate (object sender, FormatRowEventArgs e)
             {
                 var pok = e.Model as PokemonObject;
-                if (olvPokemonList.Objects.Cast<PokemonObject>()
+                if (olvPokemonList.Objects
+                    .Cast<PokemonObject>()
                     .Select(i => i.PokemonId)
-                    .Where(p => p == pok.PokemonId)
-                    .Count() > 1)
+                    .Count(p => p == pok.PokemonId) > 1)
                     e.Item.BackColor = Color.LightGreen;

                 foreach (OLVListSubItem sub in e.Item.SubItems)
@@ -538,7 +543,6 @@ namespace PokemonGo.RocketBot.Window.Forms
                     item.Text = "PowerUp";
                     item.Click += delegate { PowerUpPokemon(pokemons); };
                     cmsPokemonList.Items.Add(item);
-
                     cmsPokemonList.Items.Add(separator);

                     item = new ToolStripMenuItem();
@@ -566,6 +570,32 @@ namespace PokemonGo.RocketBot.Window.Forms
             };
         }

+        private void olvPokemonList_ButtonClick(object sender, CellClickEventArgs e)
+        {
+            try
+            {
+                var pokemon = e.Model as PokemonObject;
+                var cName = olvPokemonList.AllColumns[e.ColumnIndex].AspectToStringFormat;
+                if (cName.Equals("Transfer"))
+                {
+                    TransferPokemon(new List<PokemonData> { pokemon.PokemonData });
+                }
+                else if (cName.Equals("Power Up"))
+                {
+                    PowerUpPokemon(new List<PokemonData> { pokemon.PokemonData });
+                }
+                else if (cName.Equals("Evolve"))
+                {
+                    EvolvePokemon(new List<PokemonData> { pokemon.PokemonData });
+                }
+            }
+            catch (Exception ex)
+            {
+                Logger.Write(ex.ToString(), LogLevel.Error);
+                ReloadPokemonList();
+            }
+        }
+
         private async void TransferPokemon(IEnumerable<PokemonData> pokemons)
         {
             SetState(false);
@@ -829,6 +859,12 @@ namespace PokemonGo.RocketBot.Window.Forms

                 lblInventory.Text = itemscount + " / " + profile.PlayerData.MaxItemStorage;
             }
+            catch (ArgumentNullException)
+            {
+                Logger.Write("Please start the bot or wait until login is finished before loading Pokemon List", LogLevel.Warning);
+                SetState(true);
+                return;
+            }
             catch (Exception ex)
             {
                 Logger.Write(ex.ToString(), LogLevel.Error);
@@ -931,10 +967,5 @@ namespace PokemonGo.RocketBot.Window.Forms
         }

         #endregion POKEMON LIST
-
-        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
-        {
-            Environment.Exit(0);
-        }
     }
 }
\ No newline at end of file
diff --git a/PokemonGo.RocketBot.Window/Forms/MainForm.designer.cs b/PokemonGo.RocketBot.Window/Forms/MainForm.designer.cs
index 8844073..7d5641a 100644
--- a/PokemonGo.RocketBot.Window/Forms/MainForm.designer.cs
+++ b/PokemonGo.RocketBot.Window/Forms/MainForm.designer.cs
@@ -227,6 +227,7 @@ namespace PokemonGo.RocketBot.Window.Forms
             this.olvPokemonList.TabIndex = 25;
             this.olvPokemonList.UseCompatibleStateImageBehavior = false;
             this.olvPokemonList.View = System.Windows.Forms.View.Details;
+            this.olvPokemonList.ButtonClick += new System.EventHandler<BrightIdeasSoftware.CellClickEventArgs>(this.olvPokemonList_ButtonClick);
             //
             // pkmnName
             //
diff --git a/PokemonGo.RocketBot.Window/Forms/SettingsForm.cs b/PokemonGo.RocketBot.Window/Forms/SettingsForm.cs
index c39816d..92cfe93 100644
--- a/PokemonGo.RocketBot.Window/Forms/SettingsForm.cs
+++ b/PokemonGo.RocketBot.Window/Forms/SettingsForm.cs
@@ -16,7 +16,7 @@ namespace PokemonGo.RocketBot.Window.Forms
     {
         private DeviceHelper _deviceHelper;
         private List<DeviceInfo> _deviceInfos;
-        private bool _doNotPopulate;
+        //private bool _doNotPopulate;

         private List<ItemId> itemSettings = new List<ItemId>
         {
@@ -114,7 +114,7 @@ namespace PokemonGo.RocketBot.Window.Forms
             {
                 for (var i = 0; i < clbCatch.Items.Count; i++)
                 {
-                    var pokemonId = (PokemonId) clbCatch.Items[i];
+                    var pokemonId = (PokemonId)clbCatch.Items[i];
                     if (pokemonIdSetting == pokemonId)
                     {
                         clbCatch.SetItemChecked(i, true);
@@ -126,7 +126,7 @@ namespace PokemonGo.RocketBot.Window.Forms
             {
                 for (var i = 0; i < clbTransfer.Items.Count; i++)
                 {
-                    var pokemonId = (PokemonId) clbTransfer.Items[i];
+                    var pokemonId = (PokemonId)clbTransfer.Items[i];
                     if (pokemonIdSetting == pokemonId)
                     {
                         clbTransfer.SetItemChecked(i, true);
You may download the files in Public Git.