0

I want to set an error message in the variable txtURL but I get the error message Cannot convert from string to System.Windows.Forms.Control.

The error is on this line
frmweb.ErrorMelding.SetError(frmweb.URL, "Je hebt geen url ingegeven");

Here is the code I am using

Webbrowser_Functions.cs

public void Navigeren(frmWeb frmweb)
{
    // Als URL leeg is error melding weergeven
    if (frmweb.pu_txtURL == "")
    {
        frmweb.ErrorMelding.SetError(frmweb.URL, "Je hebt geen url ingegeven");
    }
}

frmWeb.cs

public string pu_txtURL;

public string URL
{
    get { return txtURL.Text; }
    set { txtURL.Text = value; }
}

Logical_Layer.Webbrowser_Functions ww = new Logical_Layer.Webbrowser_Functions();

public void btnNavigeer_Click(object sender, EventArgs e)
{
    txtURL.Text = pu_txtURL;
    ww.Navigeren(this);
}
4
  • The error is rather clear. You tried to pass a string to a method that expects a control. Did you mean to write SetError(frmweb.txtUrl,...) perhaps? Commented Dec 19, 2017 at 9:57
  • What is ErrorMelding what is the code of SetError ? Commented Dec 19, 2017 at 9:57
  • @Steve the Windows Forms ErrorProvider Commented Dec 19, 2017 at 9:57
  • 3
    Crystal ball says that you use the ErrorProvider component to display mistakes. Its first argument requires a Control, not a string. So you'd have to pass txtURL. Which right now is a private variable of the frmWeb class so you can't. The problem is caused by Webbrowser_Functions, it tries to do too much with variables it does not have access to. Consider adding a public method to frmWeb to report the error. Or simply making Navigeren() a method of that form class. Commented Dec 19, 2017 at 9:58

1 Answer 1

2

SetError() expects the Control you want to set the error on as first argument, not a string.

So you probably wanted something like:

frmweb.ErrorMelding.SetError(frmweb.txtURL, "Je hebt geen url ingegeven");

But actually it has a smell that the Controls of your frmweb are accessible from outside. It seems better to make Navigeren an instance method of your Form.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.