I'd like to be able to copy highlighted rows in wingrid and paste them into the same grid as new rows. I've seen other forum topics on this, but they're all very old and from what I can see they don't always work. What's the current suggested method for doing this?
Thank you for posting. The grid supports copy and pastes within a cell by default. Since you want to copy and paste rows or ranges of cells, then you need to set the AllowMultiCellOperation property.
Something like this:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
this.ultraGrid1.DisplayLayout.Override.AllowMultiCellOperations = Infragistics.Win.UltraWinGrid.AllowMultiCellOperation.All;
Attached a sample application for the reference. Let me know if you have any question.
Thanks, that mostly worked. I've got a couple issues though that I'd like to run by you.
1. When I select 2 rows to copy it tells me that I can't insert a NULL into one of the cols, but that col isn't NULL for either of the 2 rows.
2. I've got an ID col in the row and when I paste it into the new row it fires a message that the ID can't be edited and do I want to continue pasting the rest of the cols... is there a way to suppress that message?
I'm not sure about #1. You might need to provide us with a sample project so we can see what's going on there. What's the data type of that column? Does it have a ValueList or an Editor/EditorComponent assigned to it?
You could also try handling the Error event of the grid and see if it's firing and maybe it will give you more information.
And speaking of the Error event, that's the solution to your second issue. You can watch for that error and cancel the prompt like so:
private void UltraGrid1_Error(object sender, ErrorEventArgs e)
// This is probably overkill, checking all three of these.
if (e.MultiCellOperationErrorInfo.Operation == MultiCellOperation.Paste &&
e.MultiCellOperationErrorInfo.Exception is InvalidOperationException &&
// This will prevent the prompt from displaying to the user.
e.ErrorText = string.Empty;
I created a new project and a DT using my data and it works just fine. It's not tied into the DB though, so I'm thinking that something's not being built right in the query it sends. Is there a way to inspect that and see the query it's sending?
I'm not sure I am following you. What query are you referring to? The grid communicates with the local DataSource via the IBindingList interface and the BindingManager. It doesn't use any kind of queries.You could, in theory, handle the BeforeMultiCellOperation event of the grid and try to examine the contents of the ClipBoard when you perform the Paste operation. But I'm not sure what that would tell you- and the data is in a format that's a bit tricky to read. At best, that might tell you whether the problem is with the copy or the paste - if the clipboard data contained nulls then you would know something when wrong when copying. If it did not contain nulls, then something weird must be happening on the paste.