Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
260
Undo/Redo of programmatic value changes
posted

I have enabled undo/redo and it works. Because of virtualization I want to be able to paste a whole column even if you cant see all the rows, by default XamDataGrid will just not paste to anything outside the view of the screen because of row virtualization, so I am manually intercepting the ClipboardPasting event, setting e.Cancel and e.Handled to true and going through each of the values being pasted and manually setting them by doing:

 

for (int fieldNum = 0; fieldNum < e.FieldCount; fieldNum++)

{

Field field = e.GetTargetField(fieldNum);

 

if (field.Settings.AllowEdit.Value == false)

continue;

 

for (int recordNum = 0; recordNum < e.RecordCount; recordNum++)

{

DataRecord record = e.GetTargetRecord(recordNum);

Cell cell = e.GetTargetCell(recordNum, fieldNum);

CellData myCell = ((RowData)record.DataItem).Cells[(int)field.Tag];

 

object originalValue = e.Values[recordNum, fieldNum].Value;

object newValue = null;

try

{

newValue = field.Converter.Convert(originalValue, field.Settings.EditAsType, null, null);

}

catch

{

MessageBox.Show(G.Window, 

"Unable to convert...", 

"Paste Error", 

MessageBoxButton.OK);

 

continue;

}

cell.IsActive = true;

CellValuePresenter.FromCell(cell).Value = newValue;

}

}

 

This works, but now the paste cannot be undone with ctrl+z, is there something you have to do to enable undo/redo to work after setting the CellValuePresenter.Value to something in code?

Parents
No Data
Reply
  • 260
    Offline posted

    I submitted a support request(CAS-38073-0QWQYX) showing the problem with pasting that caused me to make the above workaround.

     

Children
No Data