2012-02-27 47 views
2

我想創建一個自定義用戶控件,並且我需要在設計時獲得三個數據源,displaymember和value成員。用三個數據源創建用戶控件,displaymember和valuemember

我可以得到下面的代碼數據源:

private BindingSource dataSource; 

[TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design")] 
[Category("Data")] 
[RefreshProperties(RefreshProperties.Repaint)] 
[AttributeProvider(typeof(IListSource))] 
[DefaultValue(null)] 
public BindingSource DataSource 
{ 
    get 
    { 
     return this.dataSource; 
    } 
    set 
    { 
     if (this.dataSource != value) 
     { 
      this.dataSource = value; 
     } 
    } 
} 

我不知道我必須讓valuemember和displaymember相關數據源

回答

1

的這是如何做到你所要求的教程

http://msdn.microsoft.com/en-us/library/ms233787.aspx

+0

我之前看到它,但不是很有用。 – khoshahmad 2012-02-28 13:08:23

+0

它缺少什麼? – 2012-02-28 14:04:35

+0

我之前評論過它,但它對我沒有用處。請注意它沒有列出數據源,它沒有列出displaymember,我應該輸入displaymemebr,我需要查看相關顯示成員中每個數據源的列的列表。 – khoshahmad 2012-02-28 17:21:47

0

我有一個支持查找數據綁定,而不是自定義控件,這裏的代碼屬性:

private System.Windows.Forms.ListBox dropdownsource = new ListBox(); 

    [Category("Data")] 
    [Browsable(true)] 
    [DefaultValue(null)] 
    [System.ComponentModel.Bindable(true)] 
    [TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design")] 
    [Editor("System.Windows.Forms.Design.DataSourceListEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
    public object DataSource 
    { 
     get 
     { 
      return this.dropdownsource.DataSource; 
     } 
     set 
     { 
      if (this.dropdownsource.DataSource != value) 
       this.dropdownsource.DataSource = value; 
     } 
    } 

相關問題