2010-09-10 56 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 
     } 
    } 
}