假设我有一个BindingList<Person>
,其中Person
具有名为Name
的公共字符串属性。有没有办法有效(如果不是直接)绑定到Current
属性(它是一个Person
对象),然后索引到Name
属性?绑定到绑定列表的当前属性
我想象的绑定设置类似于
nameLabel.DataBindings.Add(
new Binding("Text", this.myBindingListSource, "Current.Name", true));
或
nameLabel.DataBindings.Add(
new Binding("Text", this.myBindingListSource.Current, "Name", true));
这两种方法产生运行时错误。
目前,我只是订阅BindingList的CurrentChanged
事件并在那里处理更新。这可以工作,但如果可能的话我更喜欢DataBinding方法。
它产生一个运行时错误,说我不能绑定到'Current'。我担心我可能会试图强制BindingList做一些它并不打算做的事情。谢谢你!我喜欢这个'Format'属性。 – chessofnerd
@chessofnerd您提到'BindingList',但'BindingList'没有'Current'属性,那么如何绑定一个不存在的属性?我以为你谈到了一个'BindingSource'。 –