i used panel in the form, inside the panel checkedlistbox will appear dynamically, in the checkedlist box many checkbox will appear., when i click button, what are all the items selected in the checkedlist box should appear in datagridview., i used below coding., but no process happening
string[] total_items = new string[50];
int items = 0;
private void button1_Click(object sender, EventArgs e)
{
try
{
foreach (Control p in panel1.Controls)
{
if (p.GetType() == typeof(CheckedListBox))
{
CheckedListBox getdata = new CheckedListBox();
total_items[items] = getdata.SelectedItem.ToString();
items++;
}
}
dataGridView1.Columns.Add("Items", "Choosed Items");
for (int cnt = 0; cnt < items; cnt++)
{
dataGridView1.Rows.Add(total_items[cnt]);
}
}
catch (SqlException err)
{
MessageBox.Show(err.Message);
}
}