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);
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?
Hello,
Which version of our product are you using. I tested this with the latest service release, and it works correctly. The cells that are virtualized (are outside the viewport of the XamDataGrid) are update with the pasted values correctly and you do not need custom logic for this.
I'm using the latest 9.2 service release, the only virtualization related setting I am specifying is RecordContainerGenerationMode="Recycle"
After looking closer I found some odd behavior, it is actually calling the CellUpdating and CellUpdated events for every cell, even for rows off the screen, but for the ones off the screen it is just setting the value to what was already in that cell, instead of reading from the what its pasting from. I am pasting in simply 24 rows of numbers increasing from 1 to 24, when I click at the top of the column and hit paste the visible rows get the correct 1 through 10 rows, but all the rows that weren't visible stay at their original value.
I am using a lot of custom field settings that might be causing this? My settings are:
field.DataType = typeof(object); field.BindingPath = new PropertyPath("Cells[" + index + "].Value"); field.Settings.LabelClickAction = LabelClickAction.SortByOneFieldOnlyTriState; field.Settings.CellClickAction = CellClickAction.SelectCell; field.Settings.AllowRecordFiltering = true; field.Settings.AllowGroupBy = true; ...
field.Settings.AllowEdit = _canWrite; field.Settings.EditAsType = typeof(decimal); field.Settings.SortComparer = new DecimalSorter(); string numberFormat = "-nnn,nnn,nnn,nnn,nnn"; if (_precision > 0) numberFormat += "." + new string('n', _precision); Style editStyle = new Style(typeof(XamNumericEditor)); editStyle.Setters.Add(new Setter(XamNumericEditor.MaskProperty, numberFormat)); field.Settings.EditorType = typeof(XamNumericEditor); field.Settings.EditorStyle = editStyle; field.Converter = new DecimalConverter();
And my converter is
[ValueConversion(typeof(object), typeof(decimal))] public class DecimalConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value != null && value.GetType() == typeof(string)) { if ((string)value == string.Empty) return null; return System.Convert.ChangeType(value, typeof(decimal)); } else return value; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return value; } }
The converter never gets called with a number greater than 10