[英]How to Raise an Event Once I Reach End of Method?
How to raise combobox_SelectedIndexChanged(object sender, EventArgs e) programmatically? 如何以编程方式提高combobox_SelectedIndexChanged(object sender,EventArgs e)?
Lets say i have method called ClearFields(). 可以说我有一个称为ClearFields()的方法。 I want to call the event before i hit the end of Clearfields() method. 我想在击中Clearfields()方法的结尾之前调用该事件。
Just like calling any other method: 就像调用任何其他方法一样:
Public Sub ClearFields()
...
...
combobox_SelectedIndexChanged(Nothing, Nothing)
End Sub
It's not actually 'raising the event'... When an Event is raised, all it does is call the associated method. 它实际上不是在“引发事件”……当引发事件时,它所做的只是调用关联的方法。 combobox_SelectedIndexChanged is just a method attached to an event trigger. combobox_SelectedIndexChanged只是附加到事件触发器的方法。
If you need to pass a specific comboBox into the method, replace the first Nothing with the combo box you need to pass. 如果需要将特定的comboBox传递给方法,请用您需要传递的组合框替换第一个Nothing。
For your specific case, I think you may be able to call the OnSelectedIndexChanged
method at the end of your own method. 对于您的特定情况,我认为您可以在自己的方法末尾调用OnSelectedIndexChanged
方法。 Although it seems like clearing the contents of a combo box might raise the event anyway. 尽管清除组合框的内容似乎可能会引发该事件。
您可以通过(以编程方式)选择ListView控件中的另一个项目来引发SelectedIndexChanged
事件。
Just: 只是:
combobox_SelectedIndexChanged(null, null);
At the point in your code where you want to invoke the method. 在代码中要调用该方法的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.