标题:求教:对一个命名空间的应用为何出错,谢谢!!!
取消只看楼主
ahbc123
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-5-30
结帖率:0
 问题点数:0 回复次数:0 
求教:对一个命名空间的应用为何出错,谢谢!!!
在一个自定义组件里:
 从写的一个命定控件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 Namespace
ctedEventArgs)

求教为何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)

还请帮助,谢谢!!!
搜索更多相关主题的帖子: 空间 命名 
2013-08-14 13:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-419080-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.087224 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved