日期:2014-05-18  浏览次数:21239 次

自定义combobox的问题
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace MyCombobox
{
  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();
  }
  }
}


以上是代码 抱错为:“MyCombobox.UserControl1.Dispose(bool)”: 没有找到适合的方法来重写



我加了一下三种方法都不行
  1//public new void Dispose()
  //{
  // base.Dispose();
  // /*
  // * 其他要释放的资源
  // * */
  //}
  //public new void Dispose(bool trueOrFalse)
  //{
  // base.Dispose(trueOrFalse);
  // /*
  // * 其他要释放的资源
  // * */
  //}



  2//protected override void Dispose(bool disposing)
  //{
  // if (disposing)
  // {
  // if (components != null)
  // components.Dispose();
  // }
  // base.Dispose(disposing);
  //}



  3//protected override void Dispose(bool disposing)
  //{
  // if (disposing)
  // {
  // if (components != null)
  // components.Dispose();
  // }
  // base.Dispose(disposing);
  //}

------解决方案--------------------
C# code

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Drawing; 
using System.Data; 
using System.Text; 
using System.Windows.Forms; 

namespace ZipDemo
{
    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,