I'm in WinForms C#. I'm in a loop delegating the click to a function.
foreach (Class.Item item in _searchName)
{
indexGroup++;
if (indexGroup <= MAX_SEARCHES)
{
myCntrl = (GSSearcher)panelSearch.Controls["gsSearcher" + indexGroup.ToString()];
myCntrl.Visible = true;
myCntrl.SetId = item.Id;
myCntrl.SetText1 = item.Name;
myCntrl.SetText2 = item.Description;
string[] onlyDate = item.DateCreate.ToString().Split(' ');
myCntrl.SetText3 = onlyDate[0].ToString();
//HAY QUE MIRAR ESTO.
myCntrl.MyClick += delegate { ClickIdToLoad(item.Id); };
}
}
This is inside a searcher and everytime someone search the loop is assigning the function again. So when I put a breakpoint to the function ClickIdToLoad, this stops there a lot of times. I need to "undelegate" the function or something like this once is already delegated.