Duplicate function for MVVM data application

2 replies. Last post: October 17, 2011 10:22 AM by Michael Giger
Tags :
  • New Discussion
  • New Question
  • New Product Feedback

Hi

I use the ClientUI MVVM data application (WCF RIA SP1) Template.
I would like to integrate a duplicating function. That is, that I would like to copy the selected row and insert it as a duplicate. All column values should be copied except the primary key (GUID). This is to be regenerated by the application.

I have now created a new command (DuplicateRowCommand) in the class EditableGridViewModelBase. I've bound the command to a UXButton.

public EditableGridViewModelBase() : base()

{

// Batch update is not supported in WCF RIA Services. this.IsBatchUpdate = false; this.AutoEditOperation = false; ... this.ValidateRowCommand = new DelegateCommand(ExecuteValidateRow); this.DuplicateRowCommand = new DelegateCommand(ExecuteDuplicateRow);

}

 

private void ExecuteDuplicateRow(object parameter)

{

this.EditableProductsSource.Insert(this.SelectedItem); if (!this.IsBatchUpdate) this.SaveChanges(); else this.HasChanges = true;

}

How / where do I change the primary key? I have problems, because it is a generic class. Should I override ExecuteDuplicateRow in each ViewModel?
How do to I best this?

 
A simpler sample is to initialize default values:
How can I add default values? How do I get the "product" object?
((parameter.GetType())(parameter).ProductName = "New Product" does not work...
 
private void ExecutePrepareNewRow(object parameter)

{

// It's possible to initialize the new row with default values

// Example:

// product.ProductName = "New Product";

this.NewItem = this.EditableProductsSource.Create() as T;

this.EditableProductsSource.Insert(this.NewItem);

}

 

Thanks for help!

Michael

All times are GMT -5. The time now is 3:20 PM.
Previous Next