DragDrop from DataGrid to PictureBox

mmeasor

New member
Joined
Sep 23, 2006
Messages
3
Programming Experience
Beginner
I have old code that drags and drops from a listbox to a picturebox. What I want to do is populate a DataGrid from Access, then allow a user to drag from the datagrid, and drop a picture into the picture box. I have an idea below that I hope would work, but I do not know enough about DataGrids

1. Click on a row in the DataGrid
2. On MouseDown get then Name cell from that row, and turn it to a string
3. take that string and add .jpg
4. go to the pictures directory and get the image
5. drop it in a picture box.


Here is my old .NET 1.1 ListBox code
VB.NET:
Private Sub ListBox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox.MouseDown
        If e.Button = MouseButtons.Left Then
            If ListBox.SelectedIndex > -1 Then
                ListBox.DoDragDrop(ListBox.Items.Item(ListBx.SelectedIndex).ToString, DragDropEffects.Copy)
            End If
        End If
    End Sub
    
    Private Sub lbChngetoString_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox.SelectedIndexChanged
        Debug.WriteLine("SelectedIndexChanged - " & ListBox.SelectedItem.ToString)
    End Sub

    Private Sub PictureBox_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox.DragEnter
        If e.Data.GetDataPresent(GetType(System.String)) = True Then
            e.Effect = DragDropEffects.Copy
        End If
    End Sub

    Private Sub PictureBox_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox.DragDrop
        If Not PictureBox.Image Is Nothing Then
            PictureBox.Image.Dispose()
            PictureBox.Image = Nothing
        End If
        PictureBox.Image = Image.FromFile(CStr(e.Data.GetData(GetType(System.String))))
    End Sub

For the most part I think I can reuse this code, but the DataGrid doesn't have a SelectedItem, I can use SelectedRow, but not sure how.

Thanks for any help, or knowledge that I am dreaming.
 
Oops!!

I failed to mention that now I am using VS.net 2005 .net 2.0 and a DataGridView. Not sure if that changes anything, but there it is.
 
Back
Top