Windows 窗体 ComboBox 控件用于在下拉组合框中显示数据。默认情况下,ComboBox 控件分两个部分显示:顶部是一个允许用户键入列表项的文本框。第二个部分是列表框.
 我们就是根据它有两部分组成,来实现对现有的COMBOBOX的扩展..CODING  AS FOLLOWWING:

 public class ComboBase : System.Windows.Forms.ComboBox
 {
  System.Data.DataTable oTable = null;
  System.Data.DataView oDv     = null;
  public ComboBase()
  {
   SetIniDrop("disPlay","valPlay");
  }
  private void SetIniDrop(string DisPlay,string ValPlay)
  {
   oTable = new System.Data.DataTable("combo");
   
   oTable.Columns.Add(DisPlay,typeof(string));
   oTable.Columns.Add(ValPlay,typeof(string));  
   oTable.Rows.Add(new object[]{"",""});
   oDv = new System.Data.DataView(oTable,"","",System.Data.DataViewRowState.CurrentRows); 
   
   
   this.DataSource = oDv;
   this.DisplayMember = DisPlay;
   this.ValueMember   = ValPlay;

  }
  public void Add(string[] sender)
  {
   oTable.Rows.Add(sender); 
  }
  
  protected override void OnCreateControl()
  {
   base.OnCreateControl ();
  }

 }
}

让后我们可以通过继承该COMBOBOX来实现COMBOBOX下拉内容的自定义..
 public class MyComBase : ClassLibrary2.ComboBase
 {
  /// <summary>
  public MyComBase()
  {
   
  }
  protected override void OnCreateControl()
  {
   base.Add(new string[]{"1","ENGLISH"});
   base.Add(new string[]{"2","CHINA"});
   base.OnCreateControl ();
  }

 }

THAT'S ALL


  

相关文章:

  • 2021-12-18
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2021-05-01
  • 2021-04-23
猜你喜欢
  • 2021-08-25
  • 2022-02-15
  • 2021-09-27
  • 2022-12-23
  • 2022-01-22
  • 2021-09-24
相关资源
相似解决方案