MetalGearSolid

MetalGearSolid

  • NA
  • 15
  • 15.9k

Combobox items delete - Error

Jul 30 2012 6:37 PM
        private void Form1_Load(object sender, EventArgs e)
        {
                string[] fp = File.ReadAllLines(@"filepath.txt"); //There are 3 lines in filepath.txt
                for (int i = 0; i < fp.Length; i++)
                {
                    comboBox1.Items.Add(fp[i]);
                }
        }

        private void comboBox1_KeyDown(object sender, KeyEventArgs e)
        {

            try
            {
                if (e.KeyCode == Keys.Delete)

                        if (comboBox1.SelectedIndex != -1)
                            comboBox1.Items.RemoveAt(comboBox1.SelectedIndex);
            }
            catch { }
        }

Program gives an error in this line: (When I delete all items from combobox in debug mode, it gives an error)

    static class Program
    {
        [STAThread]
        static void Main()
        {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new form1()); //InvalidArgument=Value of '0' is not valid for 'index'.
Parameter name: index

        }
    }

What is my problem. I can't figure it out...

Answers (3)