错误:未声明"ActiveDisplayGrid1".由于其保护级别,它可能无法访问. [英] Error: 'ActiveDisplayGrid1' is not declared. It may be inaccessible due to its protection level.

查看:72
本文介绍了错误:未声明"ActiveDisplayGrid1".由于其保护级别,它可能无法访问.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用放在表格上的DataGridView进行了自定义控件.
我可以单击它并更改其属性,而不会出现任何问题.

当我尝试通过代码调用过程时,出现以下错误:
未声明"ActiveDisplayGrid1".由于其保护级别,它可能无法访问.

Intellisense无法识别控件(及其属性和方法),并给出弯曲的下划线错误.


当我双击控件(在窗体上)时,它将创建一个没有句柄的加载事件:

Private Sub ActiveDisplayGrid1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub


稍后将在窗体的InitializeComponent中创建该句柄,如下所示:

AddHandler ActiveDisplayGrid1.Load, AddressOf Me.ActiveDisplayGrid1_Load

这对我来说似乎很不寻常.

通常,加载事件是按以下方式创建的:

Private Sub ActiveDisplayGrid1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActiveDisplayGrid1.Load
End Sub



我在同一个库中有其他自定义控件,它们工作正常.我看不出代码中的差异.谁能告诉我这是怎么回事?


这是控件的代码:

Imports System
Imports System.IO
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Collections
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System.Windows.Forms.PropertyGridInternal
Imports Microsoft.Win32
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Office.Interop

Public Class ActiveDisplayGrid
    Inherits System.Windows.Forms.UserControl

    Public Sub New()
        Me.InitializeComponent()
    End Sub

... code ...

End Class

解决方案

未声明"ActiveDisplayGrid1".由于其保护级别,它可能无法访问.
根据我的可能原因:
1.该类不是内部/公共类,不可以这样使用
2.您遇到了一些隐藏类的名称空间问题.

检查它们,如果引用了相关的dll,则这里的内容全都在范围内. 问题在于,我重载了用户控件的许多(我认为无用)属性,并使其无法浏览以获取更清晰的视图. . GenerateMember属性不接受此操作,并且在没有适当的错误消息的情况下产生了设计时的麻烦.我现在明白为什么了.当我排除下面的代码后,一切都恢复了.

 私有 _GenerateMember  As  布尔
< Browsable(),DefaultValueAttribute()> _
公共 重载 属性 GenerateMember() As  布尔
    获取
        返回 ._GenerateMember
    结束 获取
    设置( ByVal  As  布尔值)
        ._GenerateMember =值
    结束 设置
结束 属性


I have made a custom control with a DataGridView that I have put on a form.
I can click on it and change it''s properties without any problems.

When I try to invoke a procedure through code it gives the following error:
''ActiveDisplayGrid1'' is not declared. It may be inaccessible due to its protection level.

Intellisense does not recognize the control (and it''s properties and methods) and gives the squiggly underline error.


When I double-click on the control (on the form), then it creates a load event without a handle:

Private Sub ActiveDisplayGrid1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub


The handle is later on created in the Form it''s InitializeComponent as follows:

AddHandler ActiveDisplayGrid1.Load, AddressOf Me.ActiveDisplayGrid1_Load

This seems unusual to me.

Normally the load event is created as follows:

Private Sub ActiveDisplayGrid1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActiveDisplayGrid1.Load
End Sub



I have other custom controls in the same library that are working correct. I can see no differences in the code. Can anyone tell me what is going on here ?


This is the code for the control:

Imports System
Imports System.IO
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Collections
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Windows.Forms
Imports System.Windows.Forms.Design
Imports System.Windows.Forms.PropertyGridInternal
Imports Microsoft.Win32
Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Office.Interop

Public Class ActiveDisplayGrid
    Inherits System.Windows.Forms.UserControl

    Public Sub New()
        Me.InitializeComponent()
    End Sub

... code ...

End Class

解决方案

''ActiveDisplayGrid1'' is not declared. It may be inaccessible due to its protection level.
Possible reasons as per me:
1. Either the class is not internal/public exposed to be used like this
2. You have some namespace issues that hides the class.

Check for them, if the related dll is referenced then it''s all about scope here. Somehow the scope is getting mangled.


The problem was that I Overloaded a number of (in my opinion useless) properties of the user control and make them not browseable in order to get a clearer view. The GenerateMember property did not accept this and generated somehow design time trouble, without a proper error message. I can now understand why. When I excluded the code below, everything was OK again.

Private _GenerateMember As Boolean
<Browsable(False), DefaultValueAttribute(False)> _
Public Overloads Property GenerateMember() As Boolean
    Get
        Return Me._GenerateMember
    End Get
    Set(ByVal value As Boolean)
        Me._GenerateMember = value
    End Set
End Property


这篇关于错误:未声明"ActiveDisplayGrid1".由于其保护级别,它可能无法访问.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆