0

My problem is mentioned in this question, but the answers are all focused on the other parts of the question.

I have this event handler in a form:

Private Sub myDataTable_ColumnChanging(ByVal sender As System.Object, ByVal e As DataColumnChangeEventArgs) Handles myDataSet.myDataTable.ColumnChanged
    If (e.ProposedValue = "") Then
        e.ProposedValue = DBNull.Value
    End If
End Sub

When I open the designer for this form, do any modifications, and save, the Handles suffix is removed from the code. I have to re-add it every time in order to have the desired effect.

I should mention that IntelliSense doesn't suggest any of the DataTables in the DataSet when I write myDataSet., but after writing the correct name of the DataTable, all the available events show up, and the code is working perfectly.

Community
  • 1
  • 1
joharei
  • 578
  • 1
  • 5
  • 22

2 Answers2

0

See if this helps:

Private Sub myDataTable_ColumnChanging(ByVal sender As System.Object, ByVal e As _
DataColumnChangeEventArgs) Handles myDataSet.Tables("myDataTable").ColumnChanged

Also make sure the dataset is declared class level. Part of your problem might be that Intellisense can't find the dataset outside of it's scope.

tinstaafl
  • 6,908
  • 2
  • 15
  • 22
  • That actually results in a compile error; "Event 'Tables' cannot be found". The DataSet is from a database, and made by using the designer (declared in the Designer.vb), so I guess it's declared in class level. – joharei Jun 24 '13 at 11:15
  • As was mentioned you'll probably have to resort to using the AddHandler statement – tinstaafl Jun 24 '13 at 17:51
0
Handles myDataSet.myDataTable.ColumnChanged

The Handles keyword is auto-generated by the designer. Used to subscribe an event from a component or a control that you dropped on the form. Your "myDataSet.myDataTable" object is clearly not such a component, I can tell from the name, it won't have the required WithEvents keyword. Looks like you typed the Handles clause yourself. The designer removes it again when it notices the discrepancy.

You'll need to use the AddHandler keyword in your code to subscribe the event.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536