用户控件上的DataSource属性显示为灰色 [英] DataSource property on a User control grayed out

查看:114
本文介绍了用户控件上的DataSource属性显示为灰色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有datagridview的用户控件,用于在弹出窗口中显示地址列表,用户可以选择。

我遵循Microsoft MSDN示例。但是,当我将构建的usercontrol拖到窗体上时,控件的属性网格中的DataSource属性仍为灰色。因此,我无法在设计时设置数据源属性。



我做错了什么?

这是我的代码:



 进口 PrismaModel 
Imports System.ComponentModel

< System.ComponentModel.ComplexBindingProperties( DataSource DataMember )GT; _
公开 AdressenControl

公开 活动 AdresDoubleClicked( ByVal adres As Adres)

公共 属性 DataSource() 作为 对象
获取
返回 .ZaDatagridView1.Datasource
结束 获取
设置 ByVal 作为 对象
.ZaDatagridView1.Datasource = .ZaDatagridView1.Datasource
结束 设置
结束 财产

公共 属性 DataMember()作为 字符串
获取
返回 .ZaDatagridView1.DataMember
结束 获取
设置 ByVal String
Me .ZaDatagridView1.DataMember = value
结束 设置
结束 属性

私有 Sub ZaDatagridView1_CellDoubleClick( ByVal sender 作为 对象 ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)句柄 ZaDatagridView1.CellDoubleClick

如果 e.RowIndex> -1 然后
Dim adres As Adres
Dim list As List( Adres)= ZaDatagridView1.Datasource
adres = list(e.RowIndex)
RaiseEvent AdresDoubleClicked(adres)
结束 如果
结束 < span class =code-keyword> Sub


End Class

解决方案

我认为你需要使用 ControlDesigner



Goodd Luck;

您好



如果你想要设置datasource属性,那么必须在用户控件设计本身上完成。不是在使用时。



但你可以在运行时分配它。在用户控件中有一个公共函数/属性,它有助于设置数据源。您可以在任何托管容器中使用,例如表单。


I have a user control with a datagridview to show an address list in a popup, that the user can choose from.
I followed a Microsoft MSDN example. However, when I drag the built usercontrol onto a form, the DataSource property in the property grid of the control remains grayed out. Thus I can't set a datasource property during desgin time.

What am I doing wrong?
This is my code:

Imports PrismaModel
Imports System.ComponentModel

<System.ComponentModel.ComplexBindingProperties("DataSource", "DataMember")> _
Public Class AdressenControl

  Public Event AdresDoubleClicked(ByVal adres As Adres)

  Public Property DataSource() As Object
    Get
      Return Me.ZaDatagridView1.Datasource
    End Get
    Set(ByVal value As Object)
      Me.ZaDatagridView1.Datasource = Me.ZaDatagridView1.Datasource
    End Set
  End Property

  Public Property DataMember() As String
    Get
      Return Me.ZaDatagridView1.DataMember
    End Get
    Set(ByVal value As String)
      Me.ZaDatagridView1.DataMember = value
    End Set
  End Property

  Private Sub ZaDatagridView1_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles ZaDatagridView1.CellDoubleClick

    If e.RowIndex > -1 Then
      Dim adres As Adres
      Dim list As List(Of Adres) = ZaDatagridView1.Datasource
      adres = list(e.RowIndex)
      RaiseEvent AdresDoubleClicked(adres)
    End If
  End Sub

End Class

解决方案

i think you need to use a ControlDesigner.

Goodd Luck;


Hi

If you want to set the datasource property then it has to be done on the user control design itself. Not while using.

But you can assign it during runtime. Have a public function/property in the user control which helps set the datasource. That you can use from any hosting container like form.


这篇关于用户控件上的DataSource属性显示为灰色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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