Allowing Control C from Datagridview in

For some reason a couple a datagridviews in my 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.
Who is Participating?
Robberbaron (robr)Commented:
I think you should add a Copy2Clip method similar to the  click event ...  or

                ' Add the selection to the clipboard.
                Clipboard.SetDataObject( _

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.
zipnoticAuthor Commented:
Private Sub dgPgs_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles dgPgs.KeyPress
    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.
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
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?
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
            Debug.Print("Control-C pressed")
        End If
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.