
Now I still do a trouble trick makes my design horrible. I use a form that include datagridview control then it'll show when i call combobox dropdown event.
Can Anyone tell me a trick or class to solve this
Any support maybe fine to me
Windows Forms General
Hi: you can see my demo put datagridview in the dropdown of combobox:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Test
{
public partial class ComboDGV : ComboBox
{
private const int WM_LBUTTONDOWN = 0x201, WM_LBUTTONDBLCLK = 0x203;
ToolStripControlHost DGVHost;
ToolStripDropDown dropDown;
DataGridView DGV=new DataGridView();
public ComboDGV()
{
this.DGV.CellClick += new DataGridViewCellEventHandler(DGV_CellClick);
InitializeComponent();
DGVHost = new ToolStripControlHost(DGV);
dropDown = new ToolStripDropDown();
dropDown.Width = this.Width;
dropDown.Items.Add(DGVHost);
}
void DGV_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (DGV[e.ColumnIndex, e.RowIndex].Value != null)
this.Text = DGV[e.ColumnIndex, e.RowIndex].Value.ToString();
else this.Text = "null";
}
public DataGridView Get_DGV
{
get { return DGVHost.Control as DataGridView; }
}
private void ShowDropDown()
{
if (dropDown != null)
{
DGVHost.Size = new Size(DropDownWidth - 2, DropDownHeight);
dropDown.Show(this, 0, this.Height);
}
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_LBUTTONDBLCLK || m.Msg == WM_LBUTTONDOWN)
{
ShowDropDown();
return;
}
base.WndProc(ref m);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (dropDown != null)
{
dropDown.Dispose();
dropDown = null;
}
}
base.Dispose(disposing);
}
protected override void OnPaint(PaintEventArgs pe)
{
// TODO: Add custom paint code here
// Calling the base class OnPaint
base.OnPaint(pe);
}
}
}