当前位置:编程学习 > C#/ASP.NET >>

自定义控件求救

扩展了一下Dev的 LookUpEdit的功能,代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.Common;
using System.Collections;
namespace EportControl
{
    public class EPortLookUpEdit:DevExpress.XtraEditors.LookUpEdit
    {
        List<string> _list = new List<string>();
        
        public EPortLookUpEdit()
        {
        }
         [Browsable(true)]
         [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content)]


        public List<string> Items
         {
             get
             {
                 return _list;
             }
             set
             {
                 _list= value;
             }
         }


        protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
        {
            //this.Properties.AllowNullInput = ;
            //this.Properties.AllowNullInput=DevExpress.Utils.
            this.Properties.NullText = "请选择";
            base.OnKeyPress(e);
            if (e.KeyChar == 27)
            {
                SendKeys.Send("^{DELETE}");
            }
            if ((e.KeyChar >= 48 && e.KeyChar <= 57) || (e.KeyChar >= 65 && e.KeyChar <= 90) || (e.KeyChar >= 97 && e.KeyChar <= 122) || ((Control.ModifierKeys & Keys.Shift) == Keys.Shift && e.KeyChar == 189))

                if (this.IsPopupOpen == false)
                {
                    this.ShowPopup();
                    this.Focus();
                    this.ItemIndex = 0;
                    SendKeys.Send("{"+e.KeyChar.ToString()+"}");
                }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            this.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            this.Properties.NullText = "请选择";
            this.Properties.SearchMode = DevExpress.XtraEditors.Controls.SearchMode.AutoComplete;
        }
        public void RestDataSource()
        {
            if (this.Properties.DataSource == null) return;
            else if (((DataTable)this.Properties.DataSource).Columns.Contains("MNEMONICCODE"))
                return;
            else if (((DataTable)this.Properties.DataSource).Columns.Contains(this.Properties.DisplayMember.ToString()))
            {
                DataColumn dc = new DataColumn();
                dc.DataType = System.Type.GetType("System.String");
                dc.ColumnName = "MNEMONICCODE";
                ((DataTable)this.Properties.DataSource).Columns.Add(dc);
                foreach (DataRow dr in ((DataTable)this.Properties.DataSource).Rows)
                {
                    dr["MNEMONICCODE"] = ChsToPinYin.GetPinYin(dr[this.Properties.DisplayMember.ToString()].ToString()).ToString().ToUpper();
                }
            }
        }

    }
}
编译成DLL后,设计该控件时提示未找到类型“System.String”上的构造函数,请高手指点一下该如何改,如果把List<string>改成List<int32>则就是成功的。 --------------------编程问答-------------------- --------------------编程问答-------------------- 帮顶.

建议加命名空间试一下.

system.text; --------------------编程问答-------------------- 哎呀,没仔细看,真丢人....
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,