Hello everybody,
A method adds items in a ListBox, in a WinForms project on .Net 5.
I should like the ListBox to systematically display the last item at the moment it is inserted.
After adding the item, I could change the selectedItem, of course.
But I feel it would be more stylish, in fact clearer, to add an event to the ListBox to select the item when it is created, no matter how it is created, rather than letting the calling code doing it.
Even if it is some more work to do ...
Here, I saw the proposal to use a generic BindingList as source of the ListBox.
But by default, when I try to use System.Windows.Forms.BindingList, it happens to be non-generic, I get error CS0308, and it appears that adding "
Oh well, at least it is compatible with the project type, no?
A method adds items in a ListBox, in a WinForms project on .Net 5.
I should like the ListBox to systematically display the last item at the moment it is inserted.
After adding the item, I could change the selectedItem, of course.
But I feel it would be more stylish, in fact clearer, to add an event to the ListBox to select the item when it is created, no matter how it is created, rather than letting the calling code doing it.
Even if it is some more work to do ...
Here, I saw the proposal to use a generic BindingList as source of the ListBox.
But by default, when I try to use System.Windows.Forms.BindingList, it happens to be non-generic, I get error CS0308, and it appears that adding "
using System.Collections.Generic
", "using System.ComponentModel
" and [System.Serializable]
is not enough. Even more, it appears that [System.Serializable]
is not used at the good place.Oh well, at least it is compatible with the project type, no?
Last edited: