Currently I have a program to display some item information. What I have is a com box
to exercise different categories, and one panel to display items per selection in the com box
.
I created my own custom control to display, but when I add it to a panel dynamically, it causes a Win32 Exception
which is Create Window handle Error
.
After testing several times, I noticed that once the panel has listed 1800 custom controls in total, the exception occurs. Is there anyone who can resolve this issue? Thanks.
private void DisplayItems(List<ITEM_DATA> ItemList)
{
DisposeControls();
int total = ItemList.Count;
ItemDisplayer itemDisplayer = null;
Application.DoEvents();
for (int i = 0; i < total / 4 + 1; i++)
{
for (int j = 0; j < 4; j++)
{
int m = (i * 4) + j;
if (m >= total)
{
return;
}
itemDisplayer = new ItemDisplayer(ItemList[m], ref labItemName);
itemDisplayer.Size = new Size(240, 80);
itemDisplayer.Location = new Point(240 * j, 80 * i);
itemDisplayer.Name = "itemDisplayer" + Convert.ToString(m);
pnlItems.Controls.Add(itemDisplayer);
}
}
}