Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 checkbox
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 13-May-13 21:22pm
Comments
Sergey Alexandrovich Kryukov at 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 at 14-May-13 2:54am
   
Please see this code for clarification
<pre lang="c#">
GroupBox[] grpBox;
CheckBox[] dayCheckBox;
int grpposition = 40;
public step2(List 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

Rate this: bad
good
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.
  Permalink  
v2
Comments
vishal deb at 14-May-13 2:51am
   
1st option is looks Good. As I already done same thing for Step1 to Step2. I used List 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();
}

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 at 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 at 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 at 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 at 14-May-13 4:49am
   
@Ankit If I pass 2 List how can I relate groupbox with checkbox any hint
AnkitGoel.com at 14-May-13 6:17am
   
what do you mean by relating them? what is your purpose?
vishal deb at 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.
AnkitGoel.com at 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
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 479
2 Maciej Los 305
3 Mathew Soji 195
4 Afzaal Ahmad Zeeshan 170
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,777
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 14 May 2013
Copyright © CodeProject, 1999-2014
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