简体   繁体   中英

VB.NET Check for keydown on dragdrop

I've tried searching quite a bit for this answer but haven't been able to find a good solution.

I have a datagridview on my form where users can drag and drop files onto the grid and certain columns are filled in. This works fine.

I want to be able to check if a user has a certain key pressed at the time the file is dropped. If so, I want to use that to add specific data to one of the columns in the datagrid.

Is this possible?

EDIT:

I have used keydown outside of dragdrop before but it seems that I'm missing something. The code I have is below. No matter what I do, I never get "T is pressed" but I always get "T is not pressed".

Private Sub frmReader_DragDrop(sender As Object, e As DragEventArgs) Handles Me.DragDrop
    Dim files As String() = CType(e.Data.GetData(DataFormats.FileDrop), String())
    If Keyboard.IsKeyDown(Keys.T) Then
        MsgBox("T is pressed.")
        ' Put certain info into the datagridview
    Else
        MsgBox("T is not pressed.")
        ' Put other data into the datagridview
    End If
End Sub

God, embarassing... I changed "Keys.T" to "Key.T" and it's working fine. Sorry for the bother.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM