Click here to Skip to main content
15,888,351 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Deserialize Json and store values [Solved] Pin
jkirkerx26-Nov-14 8:43
professionaljkirkerx26-Nov-14 8:43 
QuestionDrag drop multiple rows between datagrids Pin
tommydk26-Nov-14 1:09
tommydk26-Nov-14 1:09 
AnswerRe: Drag drop multiple rows between datagrids Pin
Eddy Vluggen26-Nov-14 8:12
professionalEddy Vluggen26-Nov-14 8:12 
GeneralRe: Drag drop multiple rows between datagrids Pin
tommydk27-Nov-14 7:55
tommydk27-Nov-14 7:55 
GeneralRe: Drag drop multiple rows between datagrids Pin
Eddy Vluggen28-Nov-14 5:26
professionalEddy Vluggen28-Nov-14 5:26 
GeneralRe: Drag drop multiple rows between datagrids Pin
tommydk29-Nov-14 6:19
tommydk29-Nov-14 6:19 
GeneralRe: Drag drop multiple rows between datagrids Pin
Eddy Vluggen30-Nov-14 4:46
professionalEddy Vluggen30-Nov-14 4:46 
GeneralRe: Drag drop multiple rows between datagrids Pin
tommydk12-Feb-15 10:18
tommydk12-Feb-15 10:18 
I finally gave up on this, and ended with this code.
Not elegant, but it works Laugh | :laugh:
I just pick up the selected rows in DGV1_DragLeave

Public Class Form1
    Dim DT1 As DataTable
    Private rowIndexFromMouseDown As Int32
    Dim MouseDwn As String
    Dim DragList As List(Of Integer)

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        FillDataInGrids()
    End Sub

    Private Sub FillDataInGrids()
        DT1 = New DataTable

        'Table 1 has four columns
        DT1.Columns.Add("Name", Type.GetType("System.String"))
        DT1.Columns.Add("Designation", Type.GetType("System.String"))
        DT1.Columns.Add("Department", Type.GetType("System.String"))
        DT1.Columns.Add("Salary", Type.GetType("System.String"))

        'Now Add some Rows in the first DataTable
        Dim Dr As DataRow
        For i = 1 To 40
            Dr = DT1.NewRow
            Dr("Name") = "Tom " & i.ToString("D3")
            Dr("Designation") = "Developer " & i.ToString("D3")
            Dr("Department") = "Engg " & i.ToString("D3")
            Dr("Salary") = "100" & i.ToString("D3")
            DT1.Rows.Add(Dr)
        Next i

        'DGV2
        DGV2.Columns.Add("Name", "Name")
        DGV2.Columns.Add("Designation", "Designation")
        DGV2.Columns.Add("Department", "Department")
        DGV2.Columns.Add("Salary", "Salary")
        DGV2.Rows.Add(5)
        'Now Bind the DataGrid to datatable 1
        DGV1.DataSource = DT1
    End Sub

    Private Sub DGV1_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles DGV1.MouseDown
        rowIndexFromMouseDown = DGV1.HitTest(e.X, e.Y).RowIndex
        If rowIndexFromMouseDown <> -1 Then
            If Control.MouseButtons = MouseButtons.Left Then
                Dim hit As DataGridView.HitTestInfo = DGV1.HitTest(e.X, e.Y)
                DGV1.DoDragDrop(DGV1.Rows(hit.RowIndex), DragDropEffects.Copy)
                MouseDwn = DGV1.Name
            End If
        End If
    End Sub

    Private Sub DGV1_DragLeave(sender As System.Object, e As System.EventArgs) Handles DGV1.DragLeave
        DragList = New List(Of Integer)
        For counter = 0 To (DGV1.SelectedCells.Count - 1)
            If Not DragList.Contains(DGV1.SelectedCells(counter).RowIndex) Then DragList.Add(DGV1.SelectedCells(counter).RowIndex)
        Next
    End Sub

    Private Sub DGV2_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles DGV2.DragEnter
        e.Effect = DragDropEffects.Copy
    End Sub

    Private Sub DGV2_DragOver(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles DGV2.DragOver
        e.Effect = DragDropEffects.Copy
    End Sub

    Private Sub DGV2_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles DGV2.DragDrop
        Dim clientPoint As Point = DGV2.PointToClient(New Point(e.X, e.Y))
        Dim hit As DataGridView.HitTestInfo = DGV2.HitTest(clientPoint.X, clientPoint.Y)
        Dim i As Integer

        If hit.RowIndex = -1 Then
            i = DGV2.NewRowIndex
        Else
            i = hit.RowIndex
        End If

        DragList.Reverse()

        For j As Integer = 0 To DragList.Count - 1
            DGV2.Rows.Insert(i)
            For c As Int32 = 0 To DGV1.Rows(j).Cells.Count - 1
                DGV2.Rows(i).Cells(c).Value = DGV1.Rows(DragList.Item(j)).Cells(c).Value
            Next
            i = i + 1
        Next
        DragList.Clear()
        MouseDwn = ""
    End Sub
End Class

GeneralRe: Drag drop multiple rows between datagrids Pin
Eddy Vluggen12-Feb-15 11:37
professionalEddy Vluggen12-Feb-15 11:37 
Questionhow to convert excel sheet to xml Pin
Member 1126441326-Nov-14 0:37
Member 1126441326-Nov-14 0:37 
AnswerRe: how to convert excel sheet to xml Pin
Eddy Vluggen26-Nov-14 8:15
professionalEddy Vluggen26-Nov-14 8:15 
Questioni need help with a vb project anything helps! :) Pin
Member 1126438325-Nov-14 17:49
Member 1126438325-Nov-14 17:49 
AnswerRe: i need help with a vb project anything helps! :) Pin
Eddy Vluggen26-Nov-14 8:19
professionalEddy Vluggen26-Nov-14 8:19 
GeneralRe: i need help with a vb project anything helps! :) Pin
Member 1126438326-Nov-14 8:31
Member 1126438326-Nov-14 8:31 
GeneralRe: i need help with a vb project anything helps! :) Pin
Eddy Vluggen26-Nov-14 10:27
professionalEddy Vluggen26-Nov-14 10:27 
GeneralRe: i need help with a vb project anything helps! :) Pin
rx7man1-Dec-14 9:30
rx7man1-Dec-14 9:30 
Questionwebbrowser class, automation, document complete Pin
jkirkerx23-Nov-14 13:56
professionaljkirkerx23-Nov-14 13:56 
AnswerRe: webbrowser class, automation, document complete [solved] Pin
jkirkerx23-Nov-14 16:58
professionaljkirkerx23-Nov-14 16:58 
AnswerRe: webbrowser class, automation, document complete Pin
Richard Deeming24-Nov-14 2:46
mveRichard Deeming24-Nov-14 2:46 
GeneralRe: webbrowser class, automation, document complete Pin
jkirkerx24-Nov-14 9:51
professionaljkirkerx24-Nov-14 9:51 
Questionexcel data validation using xml Pin
Member 1125000520-Nov-14 15:40
Member 1125000520-Nov-14 15:40 
AnswerRe: excel data validation using xml Pin
Chris Quinn20-Nov-14 20:41
Chris Quinn20-Nov-14 20:41 
Questionhow to get SQL DATA DIRECTORY PATH USING VB.NET?? Pin
yogeshysankar20-Nov-14 1:39
yogeshysankar20-Nov-14 1:39 
AnswerRe: how to get SQL DATA DIRECTORY PATH USING VB.NET?? Pin
Otekpo Emmanuel20-Nov-14 11:37
Otekpo Emmanuel20-Nov-14 11:37 
GeneralRe: how to get SQL DATA DIRECTORY PATH USING VB.NET?? Pin
yogeshysankar20-Nov-14 17:48
yogeshysankar20-Nov-14 17:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.