简体   繁体   English

Visual Studio设计器删除了句柄

[英]Visual Studio designer removes Handles

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. 当我打开此表单的设计器,进行任何修改并保存时, Handles后缀将从代码中删除。 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. 我应该提到,在编写myDataSet.时,IntelliSense不会建议DataSet中的任何DataTable myDataSet. , but after writing the correct name of the DataTable, all the available events show up, and the code is working perfectly. ,但是在编写了正确的数据表名称之后,所有可用事件都会显示出来,并且代码运行正常。

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. 问题的一部分可能是Intellisense无法在其范围之外找到数据集。

Handles myDataSet.myDataTable.ColumnChanged

The Handles keyword is auto-generated by the designer. Handles关键字由设计人员自动生成。 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. 我可以从名称中看出,您的“ myDataSet.myDataTable”对象显然不是这样的组件,它将没有必需的WithEvents关键字。 Looks like you typed the Handles clause yourself. 好像您自己键入了Handles子句。 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. 您需要在代码中使用AddHandler关键字来订阅事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM