Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3555
Has Anyone replicated the copy/past functionality of excel: read
posted
I need to be able to copy a cell and past that cell value into multiple
selected cells within the grid. I presume I have to use the built in
windows clipboard? I guess I have to create my own context menu.

Basically, I want to convert this web project by Infragisitcs to winforms. A
lot of the code is written in Javascript, which obviously does not bode well
for winform.

http://samples.infragistics.com/2007.3/webfeaturebrowser/default.htm
Spreedsheet Support Excel
Working With Excel Copy & Paste

I am trying to build the exact functionality, can anyone point me in the
right direction. Like if you notice you have to double click the cell to
change the value, but just clicking on it selects it, how do I initalize
this?
Parents
No Data
Reply
  • 370
    posted

     Hi Peryan,

    To achieve this, you must handle the keydown event, look for 'Ctrl+V' keys, check for data in the clipboard and for multiple selected cells. Once all the former conditions are met, you have to set the selected cell values with the clipboard data.

    I have a code snippet that would do what you need:


        Private Sub ugMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ugMain.KeyDown
            Select Case e.KeyCode
                Case Keys.V
                    ' check for control key down
                    If e.Control = True Then

                        ' retrieve data from clipboard
                        Dim doClipboard As DataObject = DirectCast(Clipboard.GetDataObject(), DataObject)
                        ' test for CSV data available
                        If doClipboard.GetDataPresent(DataFormats.Text, True) Then

                            ' retrieve CSV data into a memory stream
                            Dim msClipboard As String
                            msClipboard = DirectCast(doClipboard.GetData(DataFormats.Text, True), String)

                            Dim str() As String = msClipboard.Split(New String() {vbCrLf}, StringSplitOptions.RemoveEmptyEntries)
                            ' Paste one cell to multiple cells
                            If str.Length = 1 AndAlso Me.ugMain.Selected.Cells.Count > 1 Then

                                For Each cell As Infragistics.Win.UltraWinGrid.UltraGridCell In Me.ugMain.Selected.Cells
                                    cell.Value = str(0)                                
                                    ' Does not seem to work: cells are deactivated/reactivated after this sub                               
                                    cell.Selected = True
                                Next
                            End If
                        End If
                    End If
            End Select
        End Sub
     

Children
No Data