Click here to Skip to main content
15,891,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I am trying to generated the dynamic labels depending on the checked checkboxes which are dynamically created.

My .Net frame is 3.5
Here is code for dynamic checkboxes
C#
System.Windows.Forms.CheckBox[] checkBox = new System.Windows.Forms.CheckBox[bran_count];

            for (int i = 0; i < bran_count; ++i)
            {
                checkBox[i] = new CheckBox();
                checkBox[i].Name = "radio" + Convert.ToString(i);
                checkBox[i].Text = ds2.Tables[0].Rows[i][2].ToString();
                
                checkBox[i].Location = new System.Drawing.Point(125 * i, 15);
                groupBox1.Controls.Add(checkBox[i]);
                checkBox[i].CheckStateChanged += new System.EventHandler(CheckBoxCheckedChanged);
                
            }
        }
        private void CheckBoxCheckedChanged(object sender, EventArgs e)
        {
            //MessageBox.Show();
        }


Any guidance is welcome, if possible give some code snippet.
Regards
Posted
Comments
CHill60 8-May-13 9:34am    
Just to clarify ... are you wanting to do something in CheckBoxCheckedChanged but need to know which checkBox[i] has just been clicked?
vishal deb 8-May-13 9:51am    
Yes but confused what to do to get the name or reference of selected checkboxes

This will fire regardless of which checkbox is clicked but shows you how to work out which one it was
C#
private void CheckBoxCheckedChanged(object sender, EventArgs e)
{
    CheckBox c = (CheckBox)sender;
    MessageBox.Show(c.Name);
}

... and will only fire for the checkbox that was just checked
 
Share this answer
 
v2
C#
for (int i = 0; i < checkBox.length; ++i)
{
if( checkBox[i].ischecked==true)
{
//MessageBox.Show();
}
}
 
Share this answer
 

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900