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?
Hello Sean,
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.
Regards,Divya
CopyPasteUltraGrid.zip
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?
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; } }
Well, I'm out of ideas, then.
Unless you are using an old version of the controls. Perhaps this is an old bug that was already fixed.
I suppose it's also possible that something in your code is modifying the clipboard data. You might try taking a look at which events of the grid you are handling and see if maybe commenting out the code for some of those events makes the problem go away. In particular, see if you are handling Before/AfterMultiCellOperation.
If not, it looks like we will need a sample so we can reproduce the problem and debug it. If you can't reproduce the issue by creating a new sample with the same data, then perhaps you could make a copy of your real application and try to reduce it down to something we could run.
There's nothing odd about the data, it's a simple string. And it's not RO or it wouldn't be able to paste for a single row. And there's no ValueList attached to it either. It's a simple data-bound col.
The error message you are getting for #1 relates to the grid either interacting with it's own rows collection or with the local data source. So it doesn't relate to the database or any kind of query... unless, like I said, the query you are using is somehow indirectly causing this by telling the DataSource to not allow nulls in a specific field. Of course, since you already said the data is NOT null and it works for a single row, there must be something else going on there. Is there anything unusual about the DataType of the column the error is occurring on? Or is there a ValueList attached to that column? Is it possible that the column is read-only in the grid so that the new row being pasted can't write that field and that's why it's null? Is this the same Identity column from question #2?
Well that's just my guess. I wanted to see the query so I could see if that were the problem. I figured that since you're so much better at .NET than I that you would know how to do it. I'm a DBA by trade.
Well... that query would be between your database and the grid's DataSource (presumably a DataSet or DataTable). The grid has NO interaction with the DataBase or that communication. It only deals with the local data source. Unless your query is having some effect on the DataSource, like it's changing one of the fields to not allow nulls, I don't see how that could possibly have anything to do with copy and pasting.