I have a case where I need to do some special handling on a paste insert. How can I detect this? I figured I could just slap an AfterRowInsert event and catch it but I had no luck. Any thoughts on this?
Before anyone asks why I would want to do this (since maybe there is another approach I could take)…
Upon paste insert, I want to do some record checking on some unrelated tables and create some records as needed. This is inherited code and it is bastardized and doesnt align well with the Epicor SOP in the use case. With that said, I’m stuck with it.
The previous code that was there tried to make use of after field change, but it looked at three different fields to run the same code, which caused some issues.
I wonder if you can use BeforeMultiCellOperation event. Here’s a very simple example of how you might go about it. This doesn’t account for nulls or data type mismatches or other errors, it’s just something I threw together very quickly. But it should point you in the right direction.
private void ultraGrid1_BeforeMultiCellOperation(object sender, BeforeMultiCellOperationEventArgs e)
{
UltraGrid grid = (UltraGrid)sender;
if (e.Operation == MultiCellOperation.Paste)
{
if (e.Cells.ColumnCount == 1 &&
e.Cells.RowCount == 1)
{
// I think you can a e.Cancel = true
}
}
}
Of course once you add the above example assuming your grid’s name is ultraGrid1 to your Customization in C# you need to add code inside InitializeCustomCode() and DestroyCustomCode() to register and deregister the events example:
this.ultraGrid1.BeforeMultiCellOperation += new Infragistics.Win.UltraWinGrid.BeforeMultiCellOperationEventHandler(this.ultraGrid1_BeforeMultiCellOperation);
Tell me how to handle it now…
The args only have one property, IsUpdate. There doesnt seems to be a way to determine what is being copied. A roundabout way is to look at rows on Pasting, then check for new rows on Pasted.
Try the BeforeMultiCellOperation, I am sure these is something from Infragistics to detect Pastes.
The only way to detect it in the Epicor Event is to mimick Epicor’s logic, which tends to be ugly because you don’t have any Column Names define in your clipboard.
IDataObject data = Clipboard.GetDataObject();
string clipboardData;
clipboardData = data.GetData(DataFormats.Text).ToString();
if (clipboardData.Length > 1)
{
clipboardData = clipboardData.Substring(0, clipboardData.Length - 2); // Remove last two characters = \r\n
string[] splitRow = clipboardData.Split('\r'); // Split on \r instead of \n since multi-line cell values have \n
}
foreach (string listEntry in splitRow)
{
string[] splitField = listEntry.Split('\t');
for (int ifield = 0; ifield != splitField.Length; ifield++)
{
}
}
dataView.Sort – does not play nice with Paste Insert if someone is pasting out of sequence – lets say you have Seq 10, 20, 30 and 5000, 5010 and someone pastes 300, 310 – the EpiUltraGrid has 2 own events called GridPasting and GridPasted (not normal infragistics) and they don’t take in account the dataView.Sort but the DataTable and once i dropped the .Sort it works – Kinda lame, but I just added a .SortIndicator on the column, which also gets reset on GridPasting so I have to add it back in GridPasted, thats why a dataView.Sort would have helped – but life goes on!
By not having a dataView.Sort it works fine, and by having one as long as I am pasting in Sequence of the Sort Key it works fine. If you have a dataView.Sort on UD03View for example and you paste, it will try to modify, replace and what not other columns, somehow it gets confused by the Row Indexes.