描述:
ComboBox和DataGridView两个控件制作复合控件,使用WindowForm自带控件显示详细下拉列表信息项!
用最少的代码量去实现ComBoxDataGridView代码下拉框。
效果图:
代码类:
public class ComboBoxDataGridView : ComboBox
{
//系统消息消息中的鼠标点击
private const int WINDOW_MSG_BUTTONDOWN = 0x201;
// 系统消息消息中的鼠标按下事件
private const int WINDOW_MSG_BUTTONDBCLICK = 0x203;
//存放自定义控件或 Windows 窗体控件。
private ToolStripControlHost hostDataGridView;
//Menu类似menu的容器
private ToolStripDropDown dropDown;
private int dropDownViewWidth = 0;
/// <summary>
/// 下拉列表的宽度
/// 如果如果不设置此属性:默认this.Width;
/// </summary>
public int DropDownViewWidth
{
set { dropDownViewWidth = value; }
get
{
return dropDownViewWidth == 0 ? this.Width : dropDownViewWidth;
}
}
/// <summary>
/// 构造函数(默认是空的网格)
/// </summary>
public ComboBoxDataGridView()
{
DataGridView dataGridView = new DataGridView();
InitControlView(dataGridView);
}
/// <summary>