VB 动态创建的控件如何绑定事件
FunctionAddiComboBox(ByValNameAsString,ByValTextAsString,ByValdtAsDataTable,ByValWidt...
Function AddiComboBox(ByVal Name As String, ByVal Text As String, ByVal dt As DataTable, ByVal Width As Integer) As ControlDim cb AS ComboBox.......AddHandler cb.SelectedIndexChanged,AddressOf cb_SelectedIndexChanged......End FunctionPrivate Sub cb_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb.SelectedIndexChangedEnd Sub cb无法在绑定事件无法被认识,声明称全局变量也不行
展开
1个回答
2013-04-28
展开全部
大概看了一下,发现你的代码有几个错误,或者说没有写全的地方.1.Dim cb AS ComboBox,这句没有将cb实例化,需要改为Dim cb AS New ComboBox2.将Handles cb.SelectedIndexChanged这部分删去.你的本意是动态的绑定事件,结果加上这句,变成静态的绑定事件了.而且由于cb是动态添加的,无法实现静态的绑定,自然会出错了. 希望对你有所帮助.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询