Hi,
Apologies for the slow reply.
You didn't quite understand what i meant.
Add a new UserControl into your project called 'CheckedDropDown' and
paste the code below over the stuff that is automatically created.
//START of code
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace WinAppSQLTestApps
{
/// <summary>
/// Summary description for CheckedDropDown.
/// </summary>
public class CheckedDropDown : System.Windows.Forms.UserControl
{
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.CheckedListBox checkedListBox1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public CheckedDropDown()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitializeComponent call
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.checkedListBox1 = new System.Windows.Forms.CheckedListBox();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.comboBox1.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.Location = new System.Drawing.Point(0, 0);
this.comboBox1.MaxDropDownItems = 1;
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(150, 21);
this.comboBox1.TabIndex = 0;
this.comboBox1.DropDown += new
System.EventHandler(this.comboBox1_DropDown);
//
// checkedListBox1
//
this.checkedListBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.checkedListBox1.Items.AddRange(new object[] {
"Item 1",
"Item 2",
"Item 3"});
this.checkedListBox1.Location = new System.Drawing.Point(0, 21);
this.checkedListBox1.Name = "checkedListBox1";
this.checkedListBox1.Size = new System.Drawing.Size(150, 4);
this.checkedListBox1.TabIndex = 1;
this.checkedListBox1.ItemCheck += new
System.Windows.Forms.ItemCheckEventHandler(this.checkedListBox1_ItemCheck);
//
// CheckedDropDown
//
this.Controls.Add(this.checkedListBox1);
this.Controls.Add(this.comboBox1);
this.Name = "CheckedDropDown";
this.Size = new System.Drawing.Size(150, 24);
this.ResumeLayout(false);
}
#endregion
private void comboBox1_DropDown(object sender, System.EventArgs e)
{
//reveal the checked listbox and give it focus
this.Height = 128;
checkedListBox1.Focus();
}
private void checkedListBox1_ItemCheck(object sender,
System.Windows.Forms.ItemCheckEventArgs e)
{
//hide the checked listbox
this.Height = comboBox1.Height;
}
}
}
//END of code
Bear in mind that this is far from ideal! But it works.
You will need to use checkedListBox1's items since that is where your
selected items will be ... the combobox is just there so the user can
click something to cause the dropdown event (which displays your
checkedListBox).
HTH,
James.