Skip to content

Dynamically adding CheckBox Controls to TabPages

hunter

Asked Nov 28, 2006, 2:17 AM EST1 answer
Share
LinkedInX
When I try to Dynamically add CheckBox Controls to TabPages on a tabPage click,
Only one of the four CheckBox is being displayed in the tabPages.

Can anyone help me to make all 4 checkboxes(corresponding to the values:Eastern,Northern,Western and Southern of 'Select RegionDescription from Region') visible and tell what the problem is?!
Here goes the code:

Java
private void tabPage3_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=DPA1W073B;Initial Catalog=northwind;Integrated Security=SSPI");
SqlCommand cmd = new SqlCommand("Select RegionDescription from Region", conn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
int CntChkBoxes = ds.Tables[0].Rows.Count;
CheckBox chk;
for (int i = 0; i < CntChkBoxes; i++)
{
chk = new CheckBox();
chk.Text = ds.Tables[0].Rows[i][0].ToString().TrimEnd();
tabPage3.Controls.Add(chk);
}
}

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Funny. I think that actually after executing this code you have all 4 check boxes on your form, but I guess you see only the last one :) It's because first 3 boxes are hidden behind the last check box. To solve the problem just assign different locations for every box...
    0