Allowing Control C from Datagridview in VB.net

For some reason a couple a datagridviews in my vb.net application won't allow me to select rows, select individual cells, or select the whole datagridview and copy it to the clipboard.  I want to be able to copy the whole DGV over to an excel sheet or select a single cell and copy then paste it to Google for instance.  I'd like to use control c and control v like a normal application.

Any way to allow this without a lot of code?  Am I missing a setting somewhere?

Clipboardcopymode: EnableWithoutHeaderText
Adding, Deleting, Editing, Reordering is all enabled.
DGV is unbound and is filled programmatically from a database.
zipnoticAsked:
Who is Participating?
 
Robberbaron (robr)Commented:
I think you should add a Copy2Clip method similar to the  click event ...  http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.clipboardcopymode.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2  or http://www.codeproject.com/Tips/491462/Copying-DataGridView-Contents-To-Clipboard

                ' Add the selection to the clipboard.
                Clipboard.SetDataObject( _
                    Me.DataGridView1.GetClipboardContent())

Open in new window


then add an event handler for the DGV to trap keypress, specifically Ctl-C.  On this keypress, call the Copy2Clip function.
0
 
zipnoticAuthor Commented:
Private Sub dgPgs_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles dgPgs.KeyPress
       
        Debug.Print(AscW(e.KeyChar))
    End Sub

Perhaps there is something more sinister occurring.  This code produces the expected values for regular keys and for MOST ctl-? values.  When I try ctrl-C or ctrl-V the keypress event does not fire at all.  ctrl-A works fine and several other ctrl combinations...

If I read correctly, CTL-C should result in an ascii code of 3?


Any ideas?

Control-C works for every other application.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Robberbaron (robr)Commented:
i suspect that the control is trapping Ctlc-C first, but not letting you act on it.

try turning Clipboardcopymode: Disable
0
 
zipnoticAuthor Commented:
Tried Clipboardcopymode: Disable

No Luck.

I found that CTRL-Z, X, C, V does not register with the control.  All other CTRL - ?  values seem to work just fine.  

I also tried turning the forms KeyPreview: True and that also did not help.

Other Ideas?
0
 
zipnoticAuthor Commented:
I had to use the KeyUp event and look for the combination of control&C, then deal with clipboard.  Works a treat. Thanks much.

        If e.Control And e.KeyValue = 67 Then
            dgs.ClipboardCopyMode =DataGridViewClipboardCopyMode.EnableWithoutHeaderText
            Clipboard.Clear()
            Clipboard.SetDataObject(Me.dgs.GetClipboardContent())
            Debug.Print("Control-C pressed")
        End If
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.