C# Event raiser VS2005

  • Thread starter Thread starter ricardo.rcarvalho
  • Start date Start date
R

ricardo.rcarvalho

Hi.

Whenever I try to do this:

myTextBox.TextChanged += new
System.IO.FileSystemEventHandler(textChanged(myRow.Cells[1],
myTextBox.Text));

I get the error:
"Method name expected"

Can any one help me with this one?

Thanks

Ricardo Carvalho
 
In normal (1.1) usage, you specify a *method* to invoke (via the delegate
signature), not specific *code* to invoke. And that is almost certainly the
wrong signature anyway. Two options:

a: create an explicit method to handle it:

myTextBox.TextChanged+=new EventHandler(myTextBox_TextChanged);
// blah
// note: name doesn't matter
void myTextBox_TextChanged(object sender, EventArgs e)
{
textChanged(myRow.Cells[1], myTextBox.Text);
}

b: (2.0) use an anonymous (inline) method:
myTextBox.TextChanged += delegate {
textChanged(myRow.Cells[1], myTextBox.Text);
};

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top