求教:对一个命名空间的应用为何出错,谢谢!!!
在一个自定义组件里:从写的一个命定控件B2
程序代码:
Imports System.Windows.Forms Imports Public Class B2 Inherits Control Public Delegate Sub ItemSelectedEventHandler(e As HelperClasses.ItemSelectedEventArgs) ', e As CustomCollectionEditorForm.ItemSelectedEventArgs Public Event ItemSelected As ItemSelectedEventHandler Public Combo As New ComboBox() Protected Overrides Sub OnClick(e As EventArgs) MyBase.OnClick(e) RaiseEvent ItemSelected(New HelperClasses.ItemSelectedEventArgs(Combo.Items(0), 0)) End Sub End Class:
在组件里的一个属性弹出窗体上:(内有一个命名空间HelperClasses.ItemSele
程序代码:
Imports System.Drawing Imports System.Collections Imports Imports System.Windows.Forms Imports System.Reflection Imports Imports System.Data 'Imports CustomControls.Win32Controls Imports CustomControls.Enumerations 'Namespace CustomControls.CollectionEditor Public Class CustomCollectionEditorForm Inherits System.Windows.Forms.Form Private Combo As New ComboBox() .... .... Public Sub B21_ItemSelected(e As HelperClasses.ItemSelectedEventArgs) Handles B21.ItemSelected TreeView1.BeginUpdate() If Collection IsNot Nothing AndAlso e.SelectedItem IsNot Nothing Then Dim type As Type = DirectCast(e.SelectedItem, Type) Dim newCollItem As Object = CreateInstance(type) Dim newTItem As TItem = CreateTItem(newCollItem) Dim selTItem As TItem = DirectCast(TreeView1.SelectedNode, TItem) TreeView1.Nodes.Add(newTItem) End If OnItemAdded(newCollItem) TreeView1.SelectedNode = newTItem End If TreeView1.EndUpdate() End Sub Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click TreeView1.BeginUpdate() If Collection IsNot Nothing Then Dim type As Type = DirectCast(New HelperClasses.ItemSelectedEventArgs(Combo.Items(0), 0).SelectedItem, Type) Dim newCollItem As Object = CreateInstance(type) Dim newTItem As TItem = CreateTItem(newCollItem) Dim selTItem As TItem = DirectCast(TreeView1.SelectedNode, TItem) TreeView1.Nodes.Add(newTItem) End If OnItemAdded(newCollItem) TreeView1.SelectedNode = newTItem End If TreeView1.EndUpdate() End Sub Namespace HelperClasses Public Structure ItemSelectedEventArgs Private _SelectedItem As Object Private _SelectedIndex As Integer Public Sub New(SelectedItem As Object, SelectedIndex As Integer) Me._SelectedItem = SelectedItem Me._SelectedIndex = SelectedIndex End Sub Public ReadOnly Property SelectedIndex() As Integer Get Return _SelectedIndex End Get End Property Public ReadOnly Property SelectedItem() As Object Get Return _SelectedItem End Get End Property End Structure End NamespacectedEventArgs)
求教为何B2里的New HelperClasses.ItemSelectedEventArgs(Combo.Items(0), 0))不出错,而Button5里面的 Dim type As Type = DirectCast(New HelperClasses.ItemSelectedEventArgs(Combo.Items(0), 0).SelectedItem, Type)
提示错误。
错误为:System.Windows.(Int32index)
还请帮助,谢谢!!!