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...
Loading
Santhosh Kumar JayaramanPosted Aug 1, 2012, 9:28 AM
for (int i = 0; i < fp.Length; i++)
{
comboBox1.Items.Add(fp[i]);
}
If error is coming , Check fp[0] exists. If it not exists,
then start with i=1 in for loop
MetalGearSolidPosted Aug 1, 2012, 9:25 AM
Santhosh Kumar JayaramanPosted Jul 31, 2012, 1:20 AM
try this.
if (comboBox1.Items.Count>0 && comboBox1.SelectedIndex != -1)
comboBox1.Items.RemoveAt(comboBox1.SelectedIndex);