Simplified cbItem a little.

Check for null input, then null selected value; catch only happens if
the method is fed something irregular.
This commit is contained in:
Kaphotics 2016-01-21 22:40:59 -08:00
parent e70fa13d12
commit f8f0d76793
2 changed files with 4 additions and 9 deletions

View File

@ -226,13 +226,8 @@ internal static uint getHEXval(string s)
}
internal static int getIndex(ComboBox cb)
{
int val;
if (cb.SelectedValue == null) return 0;
try { val = int.Parse(cb.SelectedValue.ToString()); }
catch { val = cb.SelectedIndex; if (val < 0) val = 0; }
return val;
try { return (int)(cb?.SelectedValue ?? 0); }
catch { return Math.Max(cb.SelectedIndex, 0); }
}
internal static string getOnlyHex(string s)
{
@ -363,7 +358,7 @@ internal static DialogResult Prompt(MessageBoxButtons btn, params string[] lines
public class cbItem
{
public string Text { get; set; }
public object Value { get; set; }
public int Value { get; set; }
}
internal static List<cbItem> getCBList(string textfile, string lang)
{

View File

@ -2403,7 +2403,7 @@ public byte[] preparepkx(bool click = true)
pk6.Ball = Util.getIndex(CB_Ball);
pk6.Met_Level = Util.ToInt32(TB_MetLevel.Text);
pk6.OT_Gender = PKX.getGender(Label_OTGender.Text);
pk6.EncounterType = Util.ToInt32(CB_EncounterType.SelectedValue.ToString());
pk6.EncounterType = Util.getIndex(CB_EncounterType);
pk6.Version = Util.getIndex(CB_GameOrigin);
pk6.Country = Util.getIndex(CB_Country);
pk6.Region = Util.getIndex(CB_SubRegion);