Instead of adding each item one by one to the ListBox destinationList from the string array m_List like this:
foreach (object name in m_List)
{
    destinationList.Items.Add((string)name);
}
Is there any better way I can do it?
I don't want to bind the data to the destinationList since I want to delete some entries from the ListBox later on.
If you only want to express it more elegantly, then perhaps this will work.
stringList.ForEach(item => listBox1.Items.Add(item));
                        HTH:
    string[] list = new string[] { "1", "2", "3" };
    ObservableCollection<string> oList;
    oList = new System.Collections.ObjectModel.ObservableCollection<string>(list);
    listBox1.DataContext = oList;
    Binding binding = new Binding();
    listBox1.SetBinding(ListBox.ItemsSourceProperty, binding);
    (listBox1.ItemsSource as ObservableCollection<string>).RemoveAt(0);
Just use (ItemSource as ObservableCollection)... to work with items, and not Items.Add etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With