码迷,mamicode.com
首页 > Windows程序 > 详细

WPF DataGrid双向绑定,数据源数据更改 刷新列表(无需重新加载数据源~~~)

时间:2014-11-16 14:32:49      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:io   ar   sp   for   数据   on   cti   bs   as   

//假设变动的属性是“IsChanged”,

List<DataChangedViewModel> lstDataChanged = new List<DataChangedViewModel>();

//赋值省略

 this.dataGrid.ItemsSource = lstDataChanged;

 private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataChangedViewModel mvm = dataGrid.SelectedItem as DataChangedViewModel;
            if (mvm.IsChanged.Equals("False"))
            {
                foreach (DataChangedViewModel item in dataGrid.Items)
                {
                    if (item.Id == mvm.Id)
                    {
                        item.IsChanged= "True";
                    }
                }
            }
        }

public class DataChangedViewModel
        : INotifyPropertyChanged

//实体类需要实现INotifyPropertyChanged 接口
    {

        public event PropertyChangedEventHandler PropertyChanged;

        private string isChanged;

     public int RowNum { get; set; }
        public long Id { get; set; }
        public string No { get; set; }
        public string TypeName { get; set; }
        public string StatusName { get; set; }

        //变动的属性

    public string IsChanged
        {
            get
            {
                return isChanged;
            }
            set
            {
                isChanged= value;
                NotifyPropertyChanged("isChanged");
            }
        }

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

    }

WPF DataGrid双向绑定,数据源数据更改 刷新列表(无需重新加载数据源~~~)

标签:io   ar   sp   for   数据   on   cti   bs   as   

原文地址:http://www.cnblogs.com/WSNblogs/p/4101359.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!