I am having trouble populating a datagridview with items from a string array. Here is the code I used to call the function:
ThreadPool.QueueUserWorkItem((o) =>
ReBuildObjectExplorer();
And the function itself:
try
{
List<ExplorerItem> list = new List<ExplorerItem>();
var item = new ExplorerItem();
for (int i = 0; i < lbl.Length; i++) // lbl = string array with items
{
item.title = lbl[i].Name;
list.Add(item);
}
BeginInvoke((MethodInvoker)delegate
{
explorerList = list;
dgvObjectExplorer.RowCount = explorerList.Count;
dgvObjectExplorer.Invalidate();
});
}
catch (Exception e) { MessageBox.Show(e.ToString(); }
The problem is: Suppose there are 76 items in the array. When I use this code, it ALWAYS adds the 75th item 76 times and nothing else. Why does this happen? I can't seem to figure out what is wrong with my code.