Reputation: 3529
I'm trying to figure out a way to allow a user to paste data from the clipboard (specifically excel) into a WPF program. I figured I would need to use a DataGrid, but I can't seem to get it to go (and I was hoping to create an event handler to trigger after a user pastes something in). The data the user will paste in will be a single column with a fixed number of rows (ie 15 x 1), and will just be numbers.
Any thoughts? Thanks a lot!
Upvotes: 0
Views: 1345
Reputation: 3136
Ctrl-c in Excel puts a CSV text (actually tab separated values into clipboard).
How exactly you implement the paste/import operation depends on the context. One option would be to handle paste action with an event handler on the grid and trigger the corresponding action in your view model. Another way would be to define a button or some other element so user could explicitly trigger paste (data import) operation.
However that action in the view model would take the data in the clipboard and parse it to create one instance of appropriate object for each row and add it to the ObservableCollection binded to the grid ItemsSource property.
Upvotes: 2