gridControl.Model.ClipboardPaste += Model_ClipboardPaste;
private void Model_ClipboardPaste(object sender, GridCutPasteEventArgs e)
{
var copiedText = Clipboard.GetText();
var splittext = copiedText.Split(new String[] { "\r\n" }, StringSplitOptions.None).ToList<object>();
splittext = splittext.Where(x => !String.IsNullOrEmpty(x.ToString())).ToList<object>();
for (int i=0;i<splittext.Count;i++)
{
splittext[i] = splittext[i].ToString().Split(new String[] { "\t" }, StringSplitOptions.None).ToArray();
}
var currentCellRange = e.RangeList;
var pastingCellRange = GridRangeInfo.Cells(e.RangeList.ActiveRange.Top, e.RangeList.ActiveRange.Left, (e.RangeList.ActiveRange.Bottom + splittext.Count-1), (e.RangeList.ActiveRange.Right + (splittext[0] as String[]).Length - 1));
for (int k = pastingCellRange.Top; k <= pastingCellRange.Bottom; k++)
{
for(int l=pastingCellRange.Left;l<=pastingCellRange.Right;l++)
{
GridStyleInfo style = gridControl.Model[k, l];
if (style.CellValueType == typeof(double))
{
string text = (splittext[k - pastingCellRange.Top] as String[])[l - pastingCellRange.Left];
double value;
if (double.TryParse(text, out value))
{
if (!string.IsNullOrEmpty(style.Format))
{
style.CellValue = string.Format("{0:" + style.Format + "}", value);
}
}
}
}
}
e.Handled = true;
} |