Click here to Skip to main content
13,097,012 members (81,083 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello Every body

I am standing on a cross road with a doubt which way is the correct way.

For convenience I upload a screen shot of the Form on my server- see it for reference.

As you are seeing the image Groupbox and CheckBoxes all are dynamically created.
What I am confused about
If user select Sun Tue and Fri from XII2013SIF01 and Mon Tue Wed and Thr from XII2013SIG02 how I can pass these check boxes value to Step 3 Form on button click. In Step 3 form I need to identify days by their Group name because according to that processing will be done. What technique will be best for me please give some guidance/suggestion or advice.

Thank you everybody in advance
Posted 13-May-13 20:22pm
And what is the type of "CheckBox", exactly? There are a number of types under this simple name, depending on UI library. You should always tag it or application type.
vishal deb 14-May-13 2:54am
Please see this code for clarification
<pre lang="c#">
GroupBox[] grpBox;
CheckBox[] dayCheckBox;
int grpposition = 40;
public step2(List<string> list)
int x = list.Count;
grpBox = new GroupBox[x];

for (int i = 0; i < x; i++)
grpBox[i] = new GroupBox();
grpBox[i] = new GroupBox();
grpBox[i].Name = "gpBox" + Convert.ToString(i);
grpBox[i].Text = list[i];
grpBox[i].Location = new Point(5, grpposition);
grpBox[i].Width = 500;
grpBox[i].Height = 75;

dayCheckBox = new CheckBox[7];
String[] dayName={"Sun","Mon","Tue","Wed","Thr","Fri","Sat"};
for (int j = 0; j < 7; ++j)
dayCheckBox[j] = new CheckBox();
dayCheckBox[j].Name = "radio" + Convert.ToString(j);
dayCheckBox[j].Text = dayName[j];
dayCheckBox[j].Width = 50;
dayCheckBox[j].Location = new System.Drawing.Point(70 * j, 25);
//dayCheckBox[i].CheckStateChanged += new System.EventHandler(dayCheckBoxCheckedChanged);
grpposition += 80;

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I will suggest following three options-

1. Create a constructor on Form3 and pass all values to that constructor when you create a reference to Form3.

2. Create public variables in Form3 and set from Form2 before opening Form3 (ofcourse, a reference to Form3 is required)

3. Get a reference to Form2 from Form3 by this.ParentForm property and access the check boxes and their values (you will need to change the control's 'Modifiers' property from private to internal to access it on Form3).

If you need further help, please let me know.
vishal deb 14-May-13 2:51am
1st option is looks Good. As I already done same thing for Step1 to Step2. I used List<string> in Step1 to pass the groupBox names to the constructor of Step2 Form. And from Step2 I need both the groupbox and checkbox names respectively. And Yes Section(Groupbox) can increase.
By this way
<pre lang="c#"> list = new List<string>();

private void BatchBoxCheckedChanged(object sender, EventArgs e)
CheckBox batchBox = (CheckBox)sender;
//Here I want to store name of checkbox in array

if (batchBox.Checked == true)
private void button1_Click(object sender, EventArgs e)
step2 st2 = new step2(list);
} </pre> 14-May-13 3:02am
If you have a variable number of checkboxes OR if there are too many checkboxes then you can pass a list too..
Please mark as answer if it worths..
vishal deb 14-May-13 3:03am
How can pass the values of checkboxes with their respective groupbox via constructor. I am actually confused about this only 14-May-13 3:09am
you may either pass two lists (one for each groupbox).
pass a dictionary (key as string (grpbox + check box name), value as Boolean (checkbox value))
get checkbox value from single list. but, remember the index of checkbox in the list and get value on that basis.
vishal deb 14-May-13 4:49am
@Ankit If I pass 2 List how can I relate groupbox with checkbox any hint 14-May-13 6:17am
what do you mean by relating them? what is your purpose?
vishal deb 14-May-13 8:14am
I mean to say that if I need to fix timing for days say take an example - under group1 I have selected 3 days - Sun, Mon and Thr and from Group 2 I have selected 5 days-Mon, Tue,Wed, Thr,Fri.
Now I have to fix timing and teachers for all days in next step. So How can I adjust A teacher for Group1 Sun period 1, B teacher Sun period 2, C teacher Sun period 3, B Teacher Mon Period 1, A teacher Mon Period 2, A teacher Mon Period 3 and so on. Now you can understand Why I need to club Group and their Days respectively. 15-May-13 0:56am
That is your own logic.... i can help you only when you stuck in coding....

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 14 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100