初学小白什么都不懂,在网上查了很久的结果是绑定List是不会自动更新的,要用BindingList来实现,直接用也只能更新List增减行,修改某个数值Gridview是不会自动更新的,需要用接口INotifyPropertyChanged来实现。
public class ClassBox: INotifyPropertyChanged
{
private int _boxID;
private float _width;
private string _comment;
private string _updateTime;
private string _addTime;
private List<ClassProduct> _product = new List<ClassProduct>();
/// <summary>
/// 箱码
/// </summary>
public int BoxID
{
get { return _boxID; }
set
{
if (value != _boxID)
{
_boxID = value;
NotifyPropertyChanged();
}
}
}
/// <summary>
/// 箱子重量
/// </summary>
public float Weight
{
get { return _width; }
set
{
if (value != _width)
{
_width = value;
NotifyPropertyChanged();
}
}
}
/// <summary>
/// 备注
/// </summary>
public string Comment
{
get { return _comment; }
set
{
if (value != _comment)
{
_comment = value;
NotifyPropertyChanged();
}
}
}
/// <summary>
/// 最近更新时间
/// </summary>
public string UpdateTime
{
get { return _updateTime; }
set
{
if (value != _updateTime)
{
_updateTime = value;
NotifyPropertyChanged();
}
}
}
/// <summary>
/// 添加时间
/// </summary>
public string AddTime
{
get { return _addTime; }
set
{
if (value != _addTime)
{
_addTime = value;
NotifyPropertyChanged();
}
}
}
/// <summary>
/// 箱内物品
/// </summary>
public List<ClassProduct> Product
{
get { return _product; }
set
{
if (value != _product)
{
_product = value;
NotifyPropertyChanged();
}
}
}
public ClassBox()
{
// Product = new List<ClassProduct>();
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}