I have spent hours trying to understand what is the problem in my coding but without any much result. Hence thought of posting here for an explanation
In my UI design, I have first row of <<checkbox, textbox, textbox>>
in this order. And depending on the number of rows of result returned, I will dynamically create the same number of rows of checkbox and textboxes.
However when I try to remove the redundant rows, leaving only row 1 intact, I noticed that only some controls are being removed.
For e.g
Before deleted:
checkbox0 textbox0 tb0
checkbox1 textbox1 tb1
checkbox2 textbox2 tb2
After executing
checkbox0 textbox0 tb0
--------- -------- tb1
checkbox2 textbox2 ---
My code for removing is as below:
foreach (Control c in panel1.Controls)
{
lastChar = c.Name[c.Name.Length - 1];
lastValue = (int)Char.GetNumericValue(lastChar);
MessageBox.Show("second " + c.Name);
if (lastValue > 0 && lastValue < count)
{
panel1.Controls.Remove(c);
c.Dispose();
}
}
Rightfully foreach will run through all the controls within the panel1. But i noticed that once the Remove statement is in, the whole operation went haywire.