2013-04-09 56 views
0

我有一个列表,它用于Property Grid,我想消除通过添加按钮的可能性 - 添加。属性网格c中的列表#

但我希望能够编辑已经存在的数据。

我的列表:

private List<Pos> _position = new List<Pos>(); 

    public List<Pos> Position 
    { 
     get { return _position; } 
     set 
     { 
      _position = value; 
      NotifyPropertyChanged("Position"); 
     } 
    } 

Pos.cs:

public class Pos 
{ 
    public string Name { get; set; } 
    public double Postion { get; set; } 

    public Pos() 
     : this(null, Double.NaN) 
    { 

    } 

    public Pos(string name, double postion) 
    { 
     this.Name = name; 
     this.Postion = postion; 
    } 
} 

我试图把[ReadOnly(true)]上面所列内容,它仍然给添加的选项。

有没有人有一个想法如何做到这一点?

+0

要删除添加和删除集合编辑器的按钮? – 2013-04-09 07:41:25

+0

@SimonMourier,是的。删除或禁用它不会改变我。 – 2013-04-09 07:45:54

+0

如果您对答案感到满意,请将其标记为 – 2013-04-09 12:07:04

回答

0

我取消添加/删除,这样的选项:

我创建了一个通用类:

public class PosList<T> : List<T>, ICollection<T>, IList 
{ 

    public ValuesList(IEnumerable<T> items) : base(items) { } 

    bool ICollection<T>.IsReadOnly { get { return true; } } 

    bool IList.IsReadOnly { get { return true; } } 

} 

这给人的可能性添加/删除代码,而不是通过集合编辑器。

使用:

private PosList<Pos> _position = new PosList<Pos>(new List<Pos>()); 

public PosList<Pos> Position 
{ 
    get { return _position; } 
    set 
    { 
     _position = value; 
     NotifyPropertyChanged("Position"); 
    } 
}