Pregunta

I've got a telerik RadGridView control and I want to be able to paste from a list (notepad etc) into the grid.

The problem here is that the items being added to the grid via the ItemsSource do not have a parameterless constructor.

This isn't a problem for the standard inserting of rows because the AddingNewDataItem event operates like a factory.

Pasting doesn't seem to go via this mechanism and doesn't provide a means for creating the pasted items manually.

The PastingCellClipboardContent event doesn't allow for the Item property on the GridViewCellClipboardEventArgs parameter to be set.

From what I could gather from checking the telerik forums (see: http://www.telerik.com/forums/insert-new-rows-into-radgridview-by-copy-paste-from-excel) there is no way of providing a factory as the grid view wants to just create a new instance and then use the bound properties to shove the data in.

Am I being dim and missing something?

This seems like a ridiculously inconsistent design to me.

NOTE: Using a parameterless ctor really isn't that possible for me.

¿Fue útil?

Solución

I couldn't resolve this issue using the Telerik controls

Instead I preceded to disable paste support on the RadGridView and instead added a PreviewKeyDown event on my user control.

From there I just listened for the usual paste shortcut and decided to intercept, process and insert the data manually.

This does mean I lost the built-in extraction code and had to process the string data from the clipboard directly. Given my use-case was predominantly for importing a list of strings, I just split the clipboard string by Environment.NewLine and then split each of those by , to ensure I ended up with the maximum number of sensible elements.

While not a solution to the Telerik issue (I'm growing to dislike these controls), hopefully it provides some sort of potential resolution for people having the same problem.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top