0
votes

I have a nested ListBoxes like a warningListBox item that can contain a picturesListBox and a audioRecordListBox. When I select one element of a child ListBox (es. item of pictureListBox), I need not only to recover the selected picture item but also the item of the parent warning ListBox (item of the warningListBox). In the multimediaListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) I can recover the child item selected

((System.Windows.Controls.ListBox)sender).SelectedItem

but HOW CAN I RECOVER THE ITEM of the PARENT warningListBox??

Must I add in each ListBox child element an additional field with the id of the parent item?? ... or there is a better solution, for example navigating in the sender or using the eventArgs of the SelectionChanged event?

Waiting for some suggestions ...

Enzo Contini

1

1 Answers

0
votes

It might be easiest to make the data structure similar to the UI you have. So make the data structure nested too.

To enable tracing the parent, add a Parent property to the child items.

This way you can get the parent item like this:

var parent = ((MySubitem)((System.Windows.Controls.ListBox)sender).SelectedItem).Parent;

You might find it easier to maintain this structure than to try and trace the UI controls.