1
votes

I keep getting this error - The best overloaded method match for HomeInventory2.Form1.Form1(System.Collections.Generic.IEnumerable) has some invalid arguments - for the starred section. At the same time I am also getting this error in the same spot - Argument 1: cannot convert from 'string' to System.Collections.Generic.IEnumerable

**Sorry - I should have added, the code sends a string to another form where it is split up and placed into separate text boxes.

namespace HomeInventory2
{
    public partial class Form2 : Form
    {
        OpenFileDialog openFileDialog1 = new OpenFileDialog();
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.RichText);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Run**(new Form1(richTextBox1.Text))**;
        }
    }
}
1
In general, it would help when you ask questions if you were to include what you expect or want to happen. It's not completely clear (other than by looking at your previous questions) what your goal is from the code. That would help everyone provide you better answers. - Reed Copsey
You're passing a string to Form1's constructor, but it's complaining that you only have a parametered constructor for Form1 that takes an IEnumerable. - Joe

1 Answers

2
votes

First off, you probably don't want to call Application.Run here - you already have a form.

I suspect you want to split the rich text box content by lines, then pass this to the new form and show it. If that is the case, you can do:

    private void button2_Click(object sender, EventArgs e)
    {
        // richTextBox1.Lines is a string[], which works with IEnumerable<string> (per line)
        var form = new Form1(richTextBox1.Lines);
        // Just show the form
        form.Show(); 
    }