1、New和Update时使用
this.dataGrid1.Items.Refresh();
2、数据绑定
public class DgStaffInfo : INotifyPropertyChanged
{
private int mId;
private string mName;
public string Name
{
get { return mName; }
set { mName = value; }
}
public int ID
{
get { return mId; }
set { mId = value; }
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
数据源的创建、填充、和绑定
this.mStaffInfoList = new ObservableCollection();
mStaffInfoList.Add(new DgStaffInfo { ID = records[i].ID, Name = records[i].Name });
this.dataGrid1.ItemsSource = mStaffInfoList;