Dinesh Suthar

Dinesh Suthar

  • NA
  • 4
  • 2.1k

How to redraw the controls which were added dynamically

Jan 13 2015 4:23 AM
Hello,
Here i am selecting the items from checkedListBox and saving them in ListBox by checking them and I am generating the textboxes according to the item count of list box.
Below is code:
 
 
foreach (Object items in checkedListBox1.CheckedItems)
{                 
listBox1.Items.Add(items);               
}

int camCount = listBox1.Items.Count;          
arrCam = new TextBox[camCount]; 
int dist = 0;             
for (int i = 0; i < camCount; i++)             
{                 
TextBox tx = new TextBox();                 
arrCam[i] = tx;             
}

foreach (TextBox fortx1 in arrCam)             
{                 
fortx1.Location = new Point(448, 13 + dist);                               
groupBox8.Controls.Add(fortx1);                 
dist += 25;              
}  

here the problem is when i check all the items in checkedlistbox,items go to listbox and then generate the textboxes according to the listbox's item count.Till here it working fine,now when i uncheck any item from checkedlistbox the total no. of textboxes should also change but those textboxes are not getting redrawn only previously drawn textboxes remain in form.

Can someone help me out where I am going wrong or where is the piece of code missing?

Answers (1)