开发者

Error when trying to run method

I have made this program and I dont know how to make it run. I usualy run my methods inside the 2 big methods that I have button1_Click (private void button1_Click(object sender, EventArgs e)) and button2_Click (private void button2_Click(object sender, EventArgs e)).

I write this.Lista(); in the button1_Click method and it gives me the error: No overload for method 'Lista' takes 0 arguments.

public void Lista(object sender, EventArgs e)
{
    string[] col2 = new string[dataGridView1.Rows.Count];

    for (int i = 0; i < dataGridView1.Rows.Count; i++)

            if (col2[i] 开发者_高级运维== "Browse From File...")
            {
                DialogResult result2 = openFileDialog2.ShowDialog();
                if (result2 == DialogResult.OK)
                {
                   // filename = openFileDialog1.FileName;
                }
}
}


The first line of your code, public void Lista(object sender, EventArgs e) states that the method expects the parameters in the brackets.

So you should remove the parameters from Lista(object sender, EventArgs e) (because i see you don't use them in the method anyway)


You need to provide sender and e. Or define it as

public void Lista()
{
    string[] col2 = new string[dataGridView1.Rows.Count];

    for (int i = 0; i < dataGridView1.Rows.Count; i++)

            if (col2[i] == "Browse From File...")
            {
                DialogResult result2 = openFileDialog2.ShowDialog();
                if (result2 == DialogResult.OK)
                {
                   // filename = openFileDialog1.FileName;
                }
            }
}


You need to call the method with the correct parameters!

Your signature is:

public void Lista(object sender, EventArgs e);

So you must call it with the required parameters, such as:

Lista(this,EventArgs.Empty);

You could remove the parameters completely from your method, they are probably unneeded. You could also set up Button1 to call Lista directly, rather than using the default click handler to call this method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜