我有一个绑定到 BindingList 的 ListBox,默认情况下该 ListBox 为空。
当选定的索引更改时,它应该使用选定对象中的数据更新其他控件。
问题是 SelectedIndexChanged 事件不会在第一个条目上触发(索引从 -1 更改为 0)。
但是,当我再次单击第一个条目(尽管在这种情况下索引没有改变)以及添加更多条目时,它确实会触发。
我检查了 myListBox.SelectedIndex 属性,它实际上从 -1 更改为 0,但由于某种原因没有调用事件处理程序。有谁知道为什么这样做以及如何解决它?
这是我的代码:
public partial class main : Form
{
// The class of objects in my BindingList
[Serializable]
public class DisplayDefinition : INotifyPropertyChanged
{
private string _name;
private int _width, _height, _posx, _posy;
public string Name { get { return _name; } set { _name = value; NotifyPropertyChanged("Name"); } }
public int Width { get { return _width; } set { …Run Code Online (Sandbox Code Playgroud)