【问题标题】:custom-made UserControl property binding in WinFormsWinForms中自定义的UserControl属性绑定
【发布时间】:2016-09-19 13:43:00
【问题描述】:

我有一个定制的用户控件:

public class CustomUC : UserControl
{
    [Bindable(true)]
    private string PropertyX { get { ... } ; set { ... }; }
}

我正在从另一种形式使用它。在这个表单上,我使用的是 DataSource。

问题是我无法弄清楚如何将此 PropertyX 绑定到我的 DataSource 的某个字段。

编辑

我的DataSource 是我在设计时创建的System.Windows.Forms.BindSource 对象。我已经为此datasource 设置了一个类,以便链接到ClassA。这个类有一个属性Notes我想绑定到CustomMadeUCPropertyX...

【问题讨论】:

  • 您可以使用设计器或代码。有什么问题?
  • 你能具体说明你指的是哪个DataSource吗?像button 这样的控件?你想用这个属性做什么?
  • @rbr94,我刚刚编辑了我的帖子。

标签: c# winforms data-binding


【解决方案1】:

您应该尝试以下方式通过编码来绑定属性:

object.DataBindings.Add("PropertyX", YourDataSrouce, "columnname in your datasource")

【讨论】:

    猜你喜欢
    • 2010-12-04
    • 1970-01-01
    • 2016-12-23
    • 2011-03-17
    • 2016-04-26
    • 1970-01-01
    • 1970-01-01
    • 2012-03-16
    • 1970-01-01
    相关资源
    最近更新 更多