Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a way have items (i.e. 6 out of 12 items) automatically checked in a checked list box?

Currently, I am trying to write a code which is stating that,

When the combo box says 'sweets' in form1, the checklsitbox in form2 automatically checks 6 out of the 12 items in the checklistbox.

I'm not sure where to start

What I have tried:

I've set the combobox in form1 to public, not sure where to go from there
Posted
Updated 28-Feb-18 5:11am

Since the combo which has to be checked is in the second form, it would be better to have a public method in Form2 which would handle the logic:
C#
// In form2

public void CheckItems(string param) {
   if (param == "sweets") {
     // Code to check according to your logic
   }
}


You could call that method from form1, provided you keep in form1 a valid instance variable pointing to your actual instance of form2.
 
Share this answer
 
Comments
Maciej Los 28-Feb-18 10:57am    
If i'm not wrong, OP wants to pass data between forms. If yes, then constructor of second form should accept parameters. See OriginalGriff's tips:
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
phil.o 28-Feb-18 11:02am    
You may be right; I see it more as passing a command from form1 to form2 which would trigger the logic according to passed parameter.
But again, that was a quick thought; if you have a more complete/elaborated solution, feel free to post it, it's likely I would give it a 5 anyway.
Maciej Los 28-Feb-18 11:10am    
Your first thought is right. Deserved for 5 ;)
phil.o 28-Feb-18 11:58am    
Thanks :)
 
Share this answer
 
Comments
Karthik_Mahalingam 28-Feb-18 22:39pm    
5
Maciej Los 1-Mar-18 0:18am    
Thank you, Karthik

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