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:
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);
}
}