472,141 Members | 1,008 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,141 software developers and data experts.

Checked Combo Box.

Can anyone help me about how to create combo box with its items as
checked boxes or radio buttons. This has to be done in C#.
I have seen something similar to this named custom combo boxes but they
are in MFC I have to remain constrained only in C#.

Jan 12 '07 #1
3 22346
Hi,
There is a CheckedListBox included in the c# ToolBox you could use.

If that isn't quite what you are looking for then you could consider
making a usercontrol with a normal combo and a CheckedListBox . If you
override the dropdown event, you could display the CheckedListBox
instead of the normal dropdown list.

HTH,
James Randle.

saurabhnsit2...@gmail.com wrote:
Can anyone help me about how to create combo box with its items as
checked boxes or radio buttons. This has to be done in C#.
I have seen something similar to this named custom combo boxes but they
are in MFC I have to remain constrained only in C#.
Jan 12 '07 #2
Hi,
can you elaborate bit more on it. Because I have alraedy added some
code regarding that to dropdown event as follows:-

this.comboBox1.Items.Add(checkedListBox1);

It is just for testing whether it is added or not. It seems that
something is adding but its not displaying any checked list in drop
down list.

pigeonrandle wrote:
Hi,
There is a CheckedListBox included in the c# ToolBox you could use.

If that isn't quite what you are looking for then you could consider
making a usercontrol with a normal combo and a CheckedListBox . If you
override the dropdown event, you could display the CheckedListBox
instead of the normal dropdown list.

HTH,
James Randle.

saurabhnsit2...@gmail.com wrote:
Can anyone help me about how to create combo box with its items as
checked boxes or radio buttons. This has to be done in C#.
I have seen something similar to this named custom combo boxes but they
are in MFC I have to remain constrained only in C#.
Jan 12 '07 #3
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.ch eckedListBox1_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.

Jan 15 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by vgrssrtrs | last post: by
4 posts views Thread by Heather | last post: by
2 posts views Thread by kiranmn75 | last post: by
2 posts views Thread by saurabhnsit2002 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.