Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
In my windows application, I have combobox with check box option by following Code Project Article.

A-ComboBox-with-a-CheckedListBox-as-a-Dropdown

Its working fine but client needs like there should be Select All option in that Check box, If i select Select All option in combobox all check box items should be checked.

I have tried with ccb_ItemCheck event but not worked.

private void ccb_ItemCheck(object sender, ItemCheckEventArgs e) 
{}


Please help me to complete this operation.

Thanks in advance
Posted
Comments
CHill60 9-Oct-14 12:10pm    
You need to post the code you tried for us to work out why it didn't work
ZurdoDev 9-Oct-14 12:11pm    
Where are you stuck?
[no name] 9-Oct-14 12:11pm    
What does "but not worked" mean exactly?

I'd advise you not to use the solution in the link in production code: the architecture is seriously flawed; it uses a Form as an internal part of a Control that inherits from ComboBox which is like shooting a mouse with a cannon.

If you have to use that code, then why not just put another item in the ListView ... at the top, or the bottom ...

Assuming you start off with some items unchecked, that item reads "Check All," and, if you check it, all items are checked, and the text changes to "Uncheck All" or "Clear."

Monitor the user's selection/check/uncheck activity: the moment any item ... but this special item ... is unchecked change uncheck the special item and change its text to "Check All," and so forth.

I suggest you build your own composite UserControl which will combine a ComboBox and a ListView. It's not that difficult to do. And, if you make your own UserControl, you can add a Button to it to perform a check-all or uncheck-all function, if that's what you really want.
 
Share this answer
 
v3
Comments
Maciej Los 9-Oct-14 17:48pm    
Sounds reasonable. +5!
BillWoodruff 9-Oct-14 18:46pm    
Thank you.
Following code will be definetly work.........


On itemcheck event type following code
cmbMOPTypeADV is the control ID of checkedcombobox

private void cmbMOPTypeADV_ItemCheck(object sender, ItemCheckEventArgs e)
{
string objsender = ((System.Windows.Forms.ListBox)(sender)).Text;
int count = cmbMOPTypeADV.CheckedIndices.Count;
if (e.NewValue == CheckState.Checked)
{
count = count + 1;
}
if (objsender.ToLower() == "all" && e.NewValue == CheckState.Unchecked)
{
cmbMOPTypeADV.ItemCheck -= new System.Windows.Forms.ItemCheckEventHandler(this.cmbMOPTypeADV_ItemCheck);
UncheckedAll(cmbMOPTypeADV);
cmbMOPTypeADV.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.cmbMOPTypeADV_ItemCheck);
}
else if (objsender.ToLower() == "all" && e.NewValue == CheckState.Checked)
{
cmbMOPTypeADV.ItemCheck -= new System.Windows.Forms.ItemCheckEventHandler(this.cmbMOPTypeADV_ItemCheck);
CheckedAll(cmbMOPTypeADV);
cmbMOPTypeADV.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.cmbMOPTypeADV_ItemCheck);
}
else if ((objsender.ToLower() != "" && objsender.ToLower() != "all") && e.NewValue == CheckState.Unchecked)
{
this.cmbMOPTypeADV.ItemCheck -= new System.Windows.Forms.ItemCheckEventHandler(this.cmbMOPTypeADV_ItemCheck);
cmbMOPTypeADV.SetItemChecked(0, false);
this.cmbMOPTypeADV.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.cmbMOPTypeADV_ItemCheck);
}
else if ((objsender.ToLower() != "" && objsender.ToLower() != "all") && count == (cmbMOPTypeADV.Items.Count - 1))
{
cmbMOPTypeADV.ItemCheck -= new System.Windows.Forms.ItemCheckEventHandler(this.cmbMOPTypeADV_ItemCheck);
cmbMOPTypeADV.SetItemChecked(0, true);
cmbMOPTypeADV.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.cmbMOPTypeADV_ItemCheck);
}
}

Implement following two methods
public void CheckedAll(CheckedComboBox objCombo)
{
for (int i = 0; i < objCombo.Items.Count; i++)
{
objCombo.SetItemChecked(i, true);
}
}

public void UncheckedAll(CheckedComboBox objCombo)
{
for (int i = 0; i < objCombo.Items.Count; i++)
{
objCombo.SetItemChecked(i, false);
}
}
 
Share this answer
 
Comments
Member 13295594 3-May-18 3:01am    
nice solution.. this code worked for me...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900