Here is demo for book information to demonstrate the use of ReoGrid.Mvvm. The complete source code is in the project ReoGrid.Mvvm.Demo.
Install-Package ReoGrid.Mvvm [WorksheetAttribute(Title="Books")]publicclassBook:IRecordModel{[ColumnHeader(Index=10,IsVisible=false)]publicintId{get;set;}[ColumnHeader(Index=20,Text="Name",Width=150)]publicstringTitle{get;set;}[ColumnHeader(Index=30)]publicstringAuthor{get;set;}[ColumnHeader(Index=35,Text="Type")]publicBindingTypeBindingType{get;set;}[ColumnHeader(Index=36,Text="OnSale")]publicboolIsOnSale{get;set;}[NumberFormat(DecimalPlaces=2)][ColumnHeader(Index=40)]publicdecimalPrice{get;set;}[DateTimeFormat(CultureName="en-US")][ColumnHeader(Index=45,Text="Publish Date",Width=200)]publicDateTimePubdate{get;set;}publicintRowIndex{get;set;}}(1) Model must implement the interface IRecordModel.
IRecordModel has only one property RowIndex, You don't need to do anything with it.
(2) WorksheetAttribute is used to specify the worksheet name.
It's optional, class name would be set as the worksheet name if it's not set.
(3) in ColumnHeader Attribute, Index must be specified. others are optional.
(4) DateTimeFormatDateTimeFormat are not recommended for use for now.
These features are not well implemented in ReoGrid.OR I have some misunderstand.
privateObservableCollection<IRecordModel>_Books;privateWorksheetModel_WorksheetModel;_Books=newObservableCollection<IRecordModel>();for(inti=0;i<10;i++){Bookbook=newBook();book.Id=i;book.Title=string.Format("Title{0}",i);book.Author=string.Format("Author{0}",i);book.BindingType=BindingType.Hardback;book.IsOnSale=true;book.Price=(decimal)(i*10.1);book.Pubdate=DateTime.Now;_Books.Add(book);}// reoGridControl is the ReoGridControl control instance_WorksheetModel=newWorksheetModel(reoGridControl,typeof(Book),_Books);//If you want to check the validity of the input variables, you can implement the function._WorksheetModel.OnBeforeChangeRecord+=OnBeforeChangeRecord;privatebool?OnBeforeChangeRecord(IRecordModelrecord,PropertyInfopropertyInfo,objectnewValue){if(propertyInfo.Name.Equals("Price")){decimalprice=Convert.ToDecimal(newValue);if(price>100m)//assume the max price is 100{MessageBox.Show("Max price is 100.","Alert",MessageBoxButton.OK,MessageBoxImage.Warning);returntrue;// cancel the change}}returnnull;}// add a bookintcount=_Books.Count;Bookbook=newBook();book.Id=count;book.Title=string.Format("Title{0}",count);book.Author=string.Format("Author{0}",count);book.BindingType=BindingType.Hardback;book.IsOnSale=true;book.Price=(decimal)(count*10.11)>100m?100m:(decimal)(count*10.11);book.Pubdate=DateTime.Now;_Books.Add(book);// remove a bookif(_Books.Count>0){_Books.RemoveAt(_Books.Count-1);}// move a bookif(_Books.Count>2){_Books.Move(0,_Books.Count-1);}// edit a book(_Books[0]asBook).Price=newRandom(DateTime.Now.Millisecond).Next(1,100);// invoke UpadteRecord after editing one record._WorksheetModel.UpadteRecord(_Books[0]);