Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (1 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-http://cbsecsnip.in/screen2.jpg 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
Comments
Sergey Alexandrovich Kryukov 14-May-13 2:32am    
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.
—SA
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)
{
InitializeComponent();
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;
this.Controls.Add(grpBox[i]);

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);
grpBox[i].Controls.Add(dayCheckBox[j]);
//dayCheckBox[i].CheckStateChanged += new System.EventHandler(dayCheckBoxCheckedChanged);
}
grpposition += 80;
}</pre>

1 solution

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.
 
Share this answer
 
v2
Comments
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)
{
list.Add(batchBox.Text);
}
}
private void button1_Click(object sender, EventArgs e)
{
step2 st2 = new step2(list);
st2.ShowDialog();
} </pre>
AnkitGoel.com 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
AnkitGoel.com 14-May-13 3:09am    
you may either pass two lists (one for each groupbox).
OR
pass a dictionary (key as string (grpbox + check box name), value as Boolean (checkbox value))
OR
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

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