Multiple lists linked to one list
I am trying to link multiple ListBoxs to a List. When a ListBox in one form is updated, I want it to update the other ListBox as well.
The problem I'm running into is that it doesn't update the view in the ListBox when the underlying list is updated. If I look at the ListBox.Items in debug, I can see that all the items I add are there but not showing. Also, when I open another form that displays the list box in the ListBox, it correctly displays all the items that have already been added.
private List<String> _list;
public Form1()
{
InitializeComponent();
_list = StaticInstanceOfList.GetInstance();
listbox1.DataSource = _list;
}
public void AddStringToList(string value)
{
if (!_list.Contains(value))
{
_list.Add(value);
}
}
0
source to share
2 answers
Try to use BindingList<T>
to store your items and then assign this list to both lists via DataSource
.
+5
source to share