Skip to content

A library for the ReoGrid.Wpf binding model

License

Notifications You must be signed in to change notification settings

IUpdatable/ReoGrid.Mvvm

Repository files navigation

中文版说明

Here is demo for book information to demonstrate the use of ReoGrid.Mvvm. The complete source code is in the project ReoGrid.Mvvm.Demo.

all.gif

1. create a new WPF project.

2. insatll ReoGrid.Mvvm

Install-Package ReoGrid.Mvvm 

3. create a book model

[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.

4. in ViewModel file:

4.1 create two fields
privateObservableCollection<IRecordModel>_Books;privateWorksheetModel_WorksheetModel;
4.2 init them
_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;
4.3 implement the 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;}
4.4 add delete move or edit the model
// 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]);

About

A library for the ReoGrid.Wpf binding model

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages