Click here to Skip to main content
15,890,527 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Application Software with Online Database Pin
Richard MacCutchan26-Nov-14 20:40
mveRichard MacCutchan26-Nov-14 20:40 
AnswerRe: Application Software with Online Database Pin
Bernhard Hiller27-Nov-14 0:36
Bernhard Hiller27-Nov-14 0:36 
QuestionDeserialize Json and store values Pin
jkirkerx26-Nov-14 6:56
professionaljkirkerx26-Nov-14 6:56 
AnswerRe: Deserialize Json and store values Pin
Eddy Vluggen26-Nov-14 8:09
professionalEddy Vluggen26-Nov-14 8:09 
GeneralRe: Deserialize Json and store values Pin
jkirkerx26-Nov-14 8:44
professionaljkirkerx26-Nov-14 8:44 
AnswerRe: Deserialize Json and store values Pin
Richard Deeming26-Nov-14 8:20
mveRichard Deeming26-Nov-14 8:20 
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 
Hi
I'm having a problem in dragging and dropping multiple rows between datagrids. VB.Net can't do this by default, but i found a solution here: Drag drop multiple selected rows of datagridview with left mouse button[^]

I have put the code in a new class called DD_DataGridView.vb but I can't figure out how to use it.

I have a small test projekt, with 2 Datagridviews. Can anyone give me a hint on how to use the DD_DataGridView class from this projekt.

I'm dragging from DGV1 and dropping in DGV2.
SelectionMode is FullRowSelect
Public Class Form1
    Dim DT1 As DataTable
    Private rowIndexFromMouseDown As Int32
    Dim MouseDwn As String

    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.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 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 myType As Type = GetType(DataGridViewRow)
        Dim r As DataGridViewRow = DGV1.Rows(e.Data.GetData(myType).Index)
        Dim i As Integer

        If hit.RowIndex = -1 Then
            i = DGV2.NewRowIndex
        Else
            i = hit.RowIndex
        End If
        DGV2.Rows.Insert(i)

        For j As Integer = 0 To r.Cells.Count - 1
            DGV2.Rows(i).Cells(j).Value = r.Cells(j).Value
        Next
        MouseDwn = ""
    End Sub
End Class

I guess it's pretty simple, but I have to admit that I'm more a musician than a programmer Big Grin | :-D
Regards, Tommy
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 
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 

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.