UltraTree绑定到业务对象显示文本

时间:2012-03-05 21:32:54

标签: c# infragistics

我将UltraTree控件(版本10.3)绑定到自定义数据源,如下所示:

public void Populate(List<FilterDimension> data)
{
    DataBindings.Clear();
    DataSource = data;
    Nodes[0].DataColumnSetResolved.NodeTextColumn = Nodes[0].DataColumnSetResolved.Columns["DisplayText"];
}

我的期望是更改任何绑定的FilterDimension对象上的DisplayText属性将导致UltraTree节点的文本更新。实际上,树中的文本不会更新,PropertyChanged事件仍为null,表示UltraTree甚至不会收听此通知。如何让UltraTreeFilterDimension中听取属性更改?

以下是FilterDimension的相关代码:

internal class FilterDimension : INotifyPropertyChanged
{
    private string _displayText = null;
    private string _name = null;

    private BindingList<string> _values = new BindingList<string>();

    /// <summary>
    /// Gets or sets the display friendly name.
    /// </summary>
    public string Name
    {
        get { return _name; }
        set
        {
            _name = value;
            FirePropertyChangedNotification("Name");
            if (_displayText == null) { FirePropertyChangedNotification("DisplayText"); }
        }
    }

    /// <summary>
    /// Gets or sets the display text that is used in TreeView nodes.  When null, uses the Name.
    /// </summary>
    public string DisplayText
    {
        get { return _displayText ?? Name; }
        set { _displayText = value; FirePropertyChangedNotification("DisplayText"); }
    }

    /// <summary>
    /// Gets a read/write list of values.  Is never null.
    /// </summary>
    public BindingList<string> Values
    {
        get { return _values; }
        set { _values = value ?? new BindingList<string>(); }
    }

    #region Events

    public event PropertyChangedEventHandler PropertyChanged;

    protected void FirePropertyChangedNotification(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    #endregion
}

1 个答案:

答案 0 :(得分:1)

事实证明,我需要做的就是更改为BindingList<FilterDimension>而不是List<FilterDimension ...我完全错过了控件预计通知会从列表中冒出来。