为什么想到要自定义LookUpEdit呢,有个项目,程序需要在支持触屏的工控机上运行,传统的下拉框太小,不方便触屏操作,就想到了在原来的LookUpEdit上改一下,做一个方便触屏操作的下拉框控件。
下拉框控件修改
public class RCDropDownEdit : LookUpEdit
{
public RCDropDownEdit()
{
this.CustomDrawHeader += RCDropDownEdit_CustomDrawHeader;
this.Popup += new System.EventHandler(RCDropDownEdit_Popup);
}
//隐藏原始弹窗
private void RCDropDownEdit_CustomDrawHeader(object sender, DevExpress.XtraEditors.Popup.LookUpCustomDrawHeaderArgs e)
{
this.ClosePopup();
}
//新建弹窗
private void RCDropDownEdit_Popup(object sender, EventArgs e)
{
DataTable dt = (DataTable)this.Properties.DataSource;
FrmDropDownDoubleList frm = new FrmDropDownDoubleList(dt, this.EditValue.ToString(),coumls);
frm.ShowDialog(this.TopLevelControl);
this.EditValue = frm.GetEditvalue();
}
}
}
lookupedit 下拉框弹出来的时候,隐藏原始弹窗后,弹出自定义的弹窗。
自定义弹窗
public partial class FrmDropDownDoubleList : Form
{
int chang = 140;
DataTable dt = null;
SimpleButton choose = null;
string chooseName = null;
List<SimpleButton> simlist = new List<SimpleButton>();
public FrmDropDownDoubleList()
{
this.ClientSize = new System.Drawing.Size(269, 340);
InitializeComponent();
}
public FrmDropDownDoubleList(DataTable dt, string chooseName)
{
InitializeComponent();
this.dt = dt;
this.chooseName = chooseName;
//最多五行
if (5> (dt.Rows.Count / 6.0))
{
this.ClientSize = new System.Drawing.Size((chang + 10) * 5+ 10, 340);
}
else
{
this.ClientSize = new System.Drawing.Size((chang + 10) *(dt.Rows.Count / 6.0) + 30, 340);
}
}
}
private vo