Expecto
Expecto

Reputation: 521

overloaded method match has some invalid arguments

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))**;
        }
    }
}

Upvotes: 1

Views: 1212

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564661

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(); 
    }

Upvotes: 2

Related Questions