I'm creating dynamically multiple listboxes
in c#
using the for
loop.
I want to add to each one of them a SelectionChanged
so that when the selected item changed I display a content based on which listbox
it is and the item.
But it seems that the event is linked to only the last one:
for (int d =0; d<3; d++)
{
//list des attribut
ListBox lb = new ListBox();
lb.Width = 200;
lb.Height = 250;
for( int i=0; i< names.Length; i++)
{
lb.Items.Add(names[i]);
}
listboxes.Add(lb);
lb.SelectionChanged += (sender, e) => LBTest_SelectionChanged(sender, e, d);
ResultPalner.Children.Add(lb);
}
public void LBTest_SelectionChanged(object sender, EventArgs e, int i)
{
// Do something here according to which listbox it is!
}
Try this: