Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using winform,
Which event do I use to make sure that as I am ticking items inside a checked listbox, a textbox is populated with those values?

I am using the selectedindexchanged but it does not work accurately.
For example, I put a tick next to two items, The textbox shows only the first item.
To also get the second ticked item in th etextbox, I have to click on another item in the checklistbox.

Any thoughts please?
Thanks
Posted

I'd try the ItemCheck event[^]. The name gives it away, don't you think.

Is it possible you are getting selected items and checked items mixed up? This works for me

C#
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) {
  CheckedListBox clb = (CheckedListBox)sender;
  if (e.NewValue == CheckState.Checked) {
    textBox1.AppendText(String.Format(Environment.NewLine + "Checking {0}", clb.Items[e.Index]));
  } else {
    textBox1.AppendText(String.Format(Environment.NewLine + "Unchecking {0}", clb.Items[e.Index]));
  }
}




Alan.
 
Share this answer
 
v2
Comments
arkiboys 31-Jan-12 9:34am    
I tried this event but it still does NOT do what I am after.
i.e. if I tick two items, the second item only is shown in the textbox if I click on another item in the control.
Alan N 31-Jan-12 9:57am    
I've added a code fragment.
arkiboys 31-Jan-12 10:06am    
Please try your code and see what I mean.
Note my previous explanation.
Thanks
Alan N 31-Jan-12 10:30am    
I don't understand what you are trying to say and I would need to see how you are updating your text box before I could offer any further advice. If you are using the checked item collection bear in mind that the ItemCheck event fires before the check state of an item changes.
use OnClick event of CheckedListBox
 
Share this answer
 
Comments
arkiboys 31-Jan-12 8:58am    
There is no OnClick event for this control.
I tried the click event but it still does NOT do what I am after.
i.e. if I tick two items, the second item only is shown in the textbox if I click on another item in the control.
 
Share this answer
 

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