读书人

自定义combobox的有关问题

发布时间: 2012-01-28 22:06:13 作者: rapoo

自定义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, 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();        }        protected override void Dispose(bool disposing)        {            oDv = null;            oTable = null;            base.Dispose(disposing);        }    }} 


[解决办法]
你给了public class ComboBase的代码,但出错的却是UserControl1, 不是ComboBase

读书人网 >C#

热点推荐