2010-09-10 54 views
1

我應該通過從我的WinForms應用程序中從ComboBox派生類來創建自定義組合框。我從來沒有這樣做過,也沒有找到Google的很多好例子。從組合框派生的類型綁定自定義組合框

我需要派生自定義組合框,以便我可以將自定義組合框類型綁定到特定對象。

請您指點我正確的方向?

這是我到目前爲止。

CustomComboBox.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 

namespace MAPClient { 
    class MAPCodeComboBox : ComboBox { 

    } 
} 

我有一些具體的問題:

  1. 我需要哪些方法重寫?
  2. 如何在我的VS2010設計器模式中使用它?
+0

「哪些方法做我需要重寫?」 - 好....它需要做什麼不同?此外,你應該澄清這是否是winforms,asp.net,WPF,Silverlight等... – 2010-09-10 06:05:49

+0

如果這是你第一次使用自定義控件做任何工作,那麼你應該讀一下它?請參閱[使用.NET Framework開發自定義Windows窗體控件](http://msdn.microsoft.com/zh-cn/library/6hws6h2t.aspx) – 2010-09-10 06:08:51

+0

@Marc Gravell:它的WinForms – Moon 2010-09-10 06:37:32

回答

0

好吧,最後我有以下的自定義類型有界的組合框。讓我知道如果我做錯了,否則,希望它可以幫助別人!

MAPComboBox.cs

using System.Collections.Generic; 
using System.Windows.Forms; 

namespace MAPClient { 
    class MAPComboBox : ComboBox { 
     private MAPCodeObjectCollection MAPCodeItemCollection = null; 

     new public MAPCodeObjectCollection Items { 
      // override 
     } 

     new public List<MAPCode> DataSource { 
      // override 
     } 

     public MAPCodeComboBox() { } 
    } 
} 

MAPCodeObjectCollection.cs

using System.Windows.Forms; 

namespace MAPClient { 
    class MAPCodeObjectCollection : ComboBox.ObjectCollection { 
     public MAPCodeObjectCollection(ComboBox owner) : base(owner) { } 

     new public int Add(object item) { 
      // override 
     } 

     new public void Insert(int index, object item) { 
      // override 
     } 
    } 
}