PC Review


Reply
Thread Tools Rate Thread

Checked Combo Box.

 
 
saurabhnsit2002@gmail.com
Guest
Posts: n/a
 
      12th Jan 2007
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#.

 
Reply With Quote
 
 
 
 
pigeonrandle
Guest
Posts: n/a
 
      12th Jan 2007
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#.


 
Reply With Quote
 
saurabhnsit2002@gmail.com
Guest
Posts: n/a
 
      12th Jan 2007
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#.


 
Reply With Quote
 
pigeonrandle
Guest
Posts: n/a
 
      15th Jan 2007
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Check box checked based on combo box value Allen Browne Microsoft Access 0 1st Mar 2009 05:54 AM
Re: Check box checked based on combo box value Allen Browne Microsoft Access 1 1st Mar 2009 02:23 AM
Dynamically enable combo box if check box is checked =?Utf-8?B?TUFXSUk=?= Microsoft Excel Programming 7 26th Jun 2007 08:41 PM
In the ItemCheck handler of a checked ListView, how to find the Item.text value of the row whose checked value changed? sherifffruitfly Microsoft C# .NET 3 29th Oct 2006 01:49 AM
If box is checked Combo Box won't..... =?Utf-8?B?Tmljaw==?= Microsoft Access Forms 3 20th Jun 2006 08:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:13 PM.