The code in your comboBox2.SelectedIndexChanged handler should be as follows:
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
key = String.Empty; // reset to empty on each change
try
{
if (tab == null) // if Hashtable not yet loaded
{
tab = new Hashtable(); // now refers to field
lines = File.ReadAllLines(path); // now refers to field
foreach (string line in lines)
{
if (line.Contains("="))
{
string[] items = line.Split('=');
tab.Add(items[0], int.Parse(items[1]));
}
}
} // close the if statement here
if (tab.ContainsKey(comboBox2.SelectedItem.ToString()))
{
key = comboBox2.SelectedItem.ToString();
textBox1.Text = tab[key].ToString();
}
else
{
MessageBox.Show("Invalid Key or Command Entered....\nPlease Enter A Valid Command.");
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}