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?
I used SqlBuilder to create the sql stmts to save the changes back to the DB. That's the query I'm talking about.
It works just fine with a single row, it only fails when I choose 2 or more.
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.
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?
Hi Sean,
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) { switch (e.ErrorType) { case ErrorType.MultiCellOperation: switch (e.MultiCellOperationErrorInfo.ErrorCell.Column.Key) { case "AppointmentID": // This is probably overkill, checking all three of these. if (e.MultiCellOperationErrorInfo.Operation == MultiCellOperation.Paste && e.MultiCellOperationErrorInfo.Exception is InvalidOperationException && e.MultiCellOperationErrorInfo.Exception.Message.Contains("read-only")) { // This will prevent the prompt from displaying to the user. e.ErrorText = string.Empty; } break; } break; } }
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?