tags:

views:

63

answers:

1

I have a tableadapter and I want to do something when the RowUpdated event is fired. I can't figure out where to put the code to add the handler to the event.

public partial class MyTableAdapter
{
  void OnRowUpdated(object sender, System.Data.Odbc.OdbcRowUpdatedEventArgs e)
  {
  }
}

How do I get the code below to run when the TableAdapter is created?

Adapter.RowUpdated += 
                   new System.Data.Odbc.OdbcRowUpdatedEventHandler(OnRowUpdated);
+1  A: 

EDIT: None of the steps suggested below are useful, apparently. I'm keeping this answer here purely so that anyone else trying to answer it doesn't come up with the same suggestions.


Are you creating the TableAdapter in the designer? If so, can you not just click on the Events part of the properties page, and type "OnRowUpdated" into the RowUpdated entry?

If you're creating the adapter explicitly in your code, just add the call yourself.

Alternatively, does your partial class have a constructor which is being called? Again, if so, you can add the call there.

EDIT: Okay, so presumably this is being used in a particular page or form - can you add it after the InitializeComponent method of that page/form?

Jon Skeet
I am using the designer to create a typed dataset with a data table and table adapter. There is no events part of the properties page that I can see. As the designer has created a constructor I can't add to it in the partial class.
Simon
@Simon: I was referring to the designer where you're *using* the adapter - i.e. the form/whatever where you're including it. Not the data set designer.
Jon Skeet
I could make the OnRowUpdated handler public and use this code on the form: MyTableAdapter myAdapter = new MyTableAdapter(); myAdapter.Adapter.RowUpdated += new System.Data.Odbc.OdbcRowUpdatedEventHandler(myAdapter.OnRowUpdated);However I would prefer to do this in the adapter's partial class so that the users of the dataset don't have to remember to add this code every time they create an instance of the adapter.
Simon
Jon, there is no 'events' pane on the Form either.
Henk Holterman
Okay, it looks like this answer isn't terribly useful then... will edit to say so, but leave it up as a list of things we've tried :)
Jon Skeet