Posted 3 December 2025, 6:17 pm EST
The overall goal is when the user has a full row selected and they hit ctrl+v to paste, then it should insert new rows and paste the contents to those new rows. The issue I was having is that if a column is sorted and I insert a new blank row then it automatically moved the row to its sorted position before I have the chance to paste the contents.
I have a C1FlexGrid showing my class with auto generated columns. I set ClipboardCopyMode to ExcludeHeader and my ClipboardPasteMode to None. I then listen to the KeyDown event on my grid with the intention of doing custom clipboard pasting. In the KeyDown event my code essentially looks like this:
if (e.Key == Key.V && Keyboard.Modifiers.HasFlat(ModifierKeys.Control) && Clipboard.ContainsText() && flexGrid.Selection.ColumnCount == flexGrid.Columns.Count && flexGrid.ItemsSource is IList<MyClass> myData)
{
string[] rows = Clipboard.GetText()?.Split(new [] {'\n'}, StringSplitOptions.RemoveEmptyEntries);
int insertIdx = flexGrid.Selection.Row;
for (int i = 0; i < rows.Length; i++)
{
myData.Insert(insertIdx, new MyClass());
}
flexGrid.Select(new CellRange(insertIdx, 0, insertIdx + rows.Length, flexGrid.Columns.Count), true);
}
flexGrid.Paste();
The idea being that if a full row is selected, insert a new row for each line of text on the clipboard, select those new rows, then use flexGrid.Paste() to handle the assigning of values to MyClass.
MyClass has a DateTime field. If I sort or filter this column, then when I insert ‘new MyClass()’ the new DateTime is null and gets filtered out/sorted to the bottom. Then when I try pasting the data in it paste it to the wrong location overwriting my existing rows and leaving behind blank rows.
I tried using flexGrid.GetRowIndex(insertIdx) to get the associated grid index for the item i just inserted into my source collection, but this always returns the same insertIdx and now the sorted index(row 0). I also tried using flexGrid.SetClipString() instead of just relying on flexGrid.Paste() to insert my data, but this resulted in the same issue.
Any ideas/tips/tricks would be appreciated! I might be way overcomplicating this whole thing.
