Selecting row that was dragged and dropped in datagridview - vb.net

I created a datagridview with some sample data. When I drag a row in the datagridview to another position this works fine. The only thing I can't get working after hours of attempts is to get the row highlighted that was dragged.
In my code the row gets highlighted where the row was originally.
Below some screenshots:
As you can see I moved row 8 to row 14 but row instead of highlighting row 14 it stays on row 8.
My code stripped:
Private Sub DataGridViewForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
LoadDataGridView1()
End Sub
Public Sub LoadDataGridView1()
' Fill datasource
End Sub
Private Sub Dgv_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DatagridView1.DragDrop
' Code to move row up or down
End Sub
Private Sub Dgv_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DatagridView1.DragEnter
e.Effect = DragDropEffects.Copy
End Sub
Private Sub DataGridView_CellMouseDown(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DatagridView1.CellMouseDown
Dim dname As DataGridView = sender
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim view As DataGridViewRow = DirectCast(dname.Rows(e.RowIndex), DataGridViewRow)
If view IsNot Nothing Then
dname.DoDragDrop(view, DragDropEffects.Copy)
End If
LoadDataGridView1()
End If
End Sub

I fixed it as follows for anyone interested:
In the CellMouseDown i set the colors:
Private Sub Dgv_CellMouseDown(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DgvPersonen.CellMouseDown
Dim dname As DataGridView = sender
dname.DefaultCellStyle.BackColor = Color.White
dname.DefaultCellStyle.SelectionBackColor = Color.Tomato
dname.AlternatingRowsDefaultCellStyle.BackColor = MyCustomColor
dname.AlternatingRowsDefaultCellStyle.SelectionBackColor = Color.Tomato
When it was a left mousebutton click on a row I select the row and save the color it was:
dname.CurrentCell = dname(e.ColumnIndex, e.RowIndex)
OriginalColor = dname.Rows(OriginalRow).DefaultCellStyle.BackColor
dname.Rows(OriginalRow).DefaultCellStyle.BackColor = OriginalColor
dname.Rows(LastRow).DefaultCellStyle.BackColor = OriginalColor
Dim view As DataGridViewRow = DirectCast(dname.Rows(e.RowIndex), DataGridViewRow)
If view IsNot Nothing Then
dname.DoDragDrop(view, DragDropEffects.Copy)
End If
OriginalRow and LastRow only get set when drag&drop rows as follows:
Private Sub Dgv_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles DgvPersonen.DragDrop
Dim dname As DataGridView = sender
dname.DefaultCellStyle.BackColor = Color.White
dname.DefaultCellStyle.SelectionBackColor = Color.Tomato
dname.AlternatingRowsDefaultCellStyle.BackColor = MyCustomColor
dname.AlternatingRowsDefaultCellStyle.SelectionBackColor = Color.Tomato
Dim newRow As DataGridViewRow = dname.Rows(dname.HitTest(p.X, p.Y).RowIndex)
If newRow.Index >= 0 And newRow.Index < dname.Rows.Count Then
' Get the dropped row info
Dim oldRow As DataGridViewRow = DirectCast(e.Data.GetData(GetType(DataGridViewRow)), DataGridViewRow)
' If the two rows aren't the same it inserts dropped row
If newRow.Index <> oldRow.Index Then
OriginalRow = oldRow.Index
LastRow = newRow.Index
OriginalColor = dname.Rows(OriginalRow).DefaultCellStyle.BackColor
FillDataGridViewsOnValue()
dname.Rows(OriginalRow).DefaultCellStyle.BackColor = OriginalColor
dname.Rows(LastRow).DefaultCellStyle.BackColor = Color.Tomato
dname.Rows(LastRow).Selected = True
dname.DefaultCellStyle.BackColor = Color.White
dname.DefaultCellStyle.SelectionBackColor = Color.White
dname.AlternatingRowsDefaultCellStyle.BackColor = MyCustomColor
dname.AlternatingRowsDefaultCellStyle.SelectionBackColor = MyCustomColor
It was a lot of trial and error but it works now exactly like a want it to work.

Related

Adding Conditions to the Listboxes from .csv files

enter image description herei am looking for this problem for very long time and I have found nothing about that... :( .
So, I have 2 .csv files. In the .csv file 1 are the listboxes and all of these listboxes have one number between 1 and 6. In the .csv file 2 are some tools like (audi, bmw) and the tools have one numer between 1 and 6 too.
Example:
.csv file 1
Listbox 1 (X,Y,Length,Width) category 1
Listbox 2 (X,Y,Length,Width) category 2
Listbox 3 (X,Y,Length,Width) category 3
.csv file 2
Mercedes category 1
BMW category 2
Audi category 3
So, I want compare the 2 .csv files and allow the listbox 2 for only BMW to drag and drop.
If I drop categroy 2 to category 1 in the listbox, it should be false.
Imports System.Windows.Forms
Imports System.IO
Public Class Form2
Private meineListBoxen As New List(Of ListBox)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim strZeilen() As String
Dim strFelder() As String
Dim strZeilen0() As String
Dim strZeilen2() As String = IO.File.ReadAllLines("K:\Ruebel_Andreas\Modellpflege\Datenerfassung.csv")
Dim strFelder1() As String
strZeilen = File.ReadAllLines("K:\Ruebel_Andreas\Modellpflege\listboxpflege.csv")
strZeilen0 = IO.File.ReadAllLines("K:\Ruebel_Andreas\Modellpflege\Spritzguss.csv")
For i As Integer = 1 To strZeilen.GetUpperBound(0)
strFelder = strZeilen(i).Split(";")
meineListBoxen.Add(New ListBox)
With meineListBoxen(i - 1)
.Left = strFelder(0)
.Top = strFelder(1)
.Width = strFelder(2)
.Height = strFelder(3)
End With
Me.Controls.Add(meineListBoxen(i - 1))
Me.meineListBoxen(i - 1).AllowDrop = True
AddHandler meineListBoxen(i - 1).MouseDown, AddressOf meineListbox_MouseDown
AddHandler meineListBoxen(i - 1).DragDrop, AddressOf meineListbox_DragDrop
AddHandler meineListBoxen(i - 1).DragEnter, AddressOf meineListbox_DragEnter
Next
For a As Integer = 0 To strZeilen0.GetUpperBound(0)
Me.meineListBoxen(1 - 1).Items.Add(strZeilen0(a).Substring(0, strZeilen0(a).IndexOf(";")))
Next
For j As Integer = 1 To strZeilen2.GetUpperBound(0)
strFelder1 = strZeilen2(j).Split(" ")
With meineListBoxen(j)
.Items.Add(strFelder1(4))
End With
For Each itm In meineListBoxen(j).Items
If meineListBoxen(1 - 1).Items.Contains(itm) Then meineListBoxen(1 - 1).Items.Remove(itm)
Next
Next
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
Me.lblMaus.Text = "X: " & e.X & " , Y:" & e.Y
End Sub
Private source As ListBox
Private sourceIndex As Integer
Private Sub meineListbox_MouseDown(ByVal sendre As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Dim aPoint As Point
Dim lbx As ListBox
Dim aIndex As Integer
lbx = CType(sendre, ListBox)
aPoint = New Point(e.X, e.Y)
aIndex = lbx.IndexFromPoint(aPoint)
Try
If aIndex <= 0 Then
source = lbx
sourceIndex = aIndex
lbx.DoDragDrop(lbx.Items(aIndex), DragDropEffects.All)
End If
Catch ex As Exception
MessageBox.Show("Bitte wählen Sie ein Werkzeug aus")
End Try
End Sub
Private Sub meineListbox_DragDrop(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.DragEventArgs)
Dim lbx As ListBox
lbx = CType(sender, ListBox)
If Not source Is Nothing Then
source.Items.RemoveAt(sourceIndex)
End If
lbx.Items.Add(e.Data.GetData(DataFormats.Text))
End Sub
Private Sub meineListbox_DragEnter(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.DragEventArgs)
If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.All
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub cmdSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Speichern.Click
Dim w As New IO.StreamWriter("K:\Ruebel_Andreas\Modellpflege\Datenerfassung.csv")
For i = 0 To meineListBoxen.Count - 1
w.WriteLine(meineListBoxen.Item(i))
Next
w.Close()
End Sub
Private Sub WerkzeugHinzufügen_Click(sender As Object, e As EventArgs) Handles WerkzeugHinzufügen.Click
Process.Start("K:\Ruebel_Andreas\Modellpflege\Spritzguss.csv")
End Sub
Private Sub StellplatzHinzufügen_Click(sender As Object, e As EventArgs) Handles StellplatzHinzufügen.Click
Process.Start("K:\Ruebel_Andreas\Modellpflege\listboxpflege.csv")
End Sub
End Class
Private Sub cmdSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Speichern.Click
Using w As New StreamWriter("K:\Ruebel_Andreas\Modellpflege\Datenerfassung.csv")
For i = 0 To meineListBoxen.Count - 1
w.WriteLine(meineListBoxen.Item(i))
Next
End Using
End Sub
I find it odd that the Handles clause does not match the name of the method. The default would be Private Sub Speichern_Click
StreamWriter needs to be disposed. Using...End Using blocks will handle this even if there is an error.
Let's say you have 3 list boxes. Your loop will go from index 0 to index 2. WriteLine will call ToString on each item in the list of ListBox. I don't believe that a ListBox provides an implementation of ToString so you will get the fully qualified name of the object's type. I don't think you want this.
Private Sub cmdSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Speichern.Click
Using w As New StreamWriter("K:\Ruebel_Andreas\Modellpflege\Datenerfassung.csv")
For Each LB As ListBox In meineListBoxen
For Each item As String In LB.Items
w.WriteLine(item)
Next
Next
End Using
End Sub
You can initialize your variables as you declare them and with Option Infer they will be strongly typed (only works for local variables.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim strZeilen2 = File.ReadAllLines("K:\Ruebel_Andreas\Modellpflege\Datenerfassung.csv")
Dim strZeilen = File.ReadAllLines("K:\Ruebel_Andreas\Modellpflege\listboxpflege.csv")
Dim strZeilen0 = File.ReadAllLines("K:\Ruebel_Andreas\Modellpflege\Spritzguss.csv")
For i = 1 To strZeilen.GetUpperBound(0) 'Why are skipping the first line?
Dim strFelder = strZeilen(i).Split(";"c)
Dim LB As New ListBox
With LB
.Left = CInt(strFelder(0))
.Top = CInt(strFelder(1))
.Width = CInt(strFelder(2))
.Height = CInt(strFelder(3))
.AllowDrop = True
.Name = "ListBox" & i 'In case you need to refer to the control be name
End With
If i = 1 Then
For a As Integer = 0 To strZeilen0.GetUpperBound(0)
LB.Items.Add(strZeilen0(a).Substring(0, strZeilen0(a).IndexOf(";")))
Next
End If
AddHandler LB.MouseDown, AddressOf meineListbox_MouseDown
AddHandler LB.DragDrop, AddressOf meineListbox_DragDrop
AddHandler LB.DragEnter, AddressOf meineListbox_DragEnter
'I fleshed out the control before adding to the collections
Controls.Add(LB)
meineListBoxen.Add(LB)
Next
For j = 1 To strZeilen2.GetUpperBound(0) 'Again skipping first line, perhaps it is a title line
Dim strFelder1 = strZeilen2(j).Split(" "c)
meineListBoxen(j).Items.Add(strFelder1(4)) 'You are skipping the first list box
For Each itm In meineListBoxen(j).Items
If meineListBoxen(0).Items.Contains(itm) Then
meineListBoxen(0).Items.Remove(itm)
End If
Next
Next
End Sub
No need to define a point, just pass the coordinates to the IndexFromPoint method. You can use DirectCast to get the ListBox since we are sure the sender is a ListBox. DirectCast skips some of the checks that CType does so the method so is a bit faster. I am not sure if the check on the value of aIndex is necessary. Exception handling is heavy and shouldn't be used for a simple value check.
Private Sub meineListbox_MouseDown(sender As System.Object, e As System.Windows.Forms.MouseEventArgs)
Dim lbx = DirectCast(sender, ListBox)
Dim aIndex = lbx.IndexFromPoint(e.X, e.Y)
If aIndex < 0 Then
MessageBox.Show("Bitte wählen Sie ein Werkzeug aus")
Else
source = lbx
sourceIndex = aIndex
lbx.DoDragDrop(lbx.Items(aIndex), DragDropEffects.All)
End If
End Sub
Use IsNot when checking for null objects.
Private Sub meineListbox_DragDrop(sender As System.Object, e As System.Windows.Forms.DragEventArgs)
Dim lbx = DirectCast(sender, ListBox)
If source IsNot Nothing Then
source.Items.RemoveAt(sourceIndex)
End If
lbx.Items.Add(e.Data.GetData(DataFormats.Text))
End Sub
Updating this label over and over will just slow things down. Delete this Sub.
'Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
'lblMaus.Text = "X: " & e.X & " , Y: " & e.Y
'End Sub
I can't help more without correct data from your files. At one point, you are splitting by a semicolon and there aren't any in your sample data! The file content you showed is certainly not a CSV file.

Smart Phone Like Scrolling Solution issue (vb.net)

This solution seems to be the best one out there and the most commonly accepted one - however, if you scroll to the bottom and touch a the actual flowcontrol behind the buttons (I tried to make this so that there would be empty space to make this sample test easier), you then have to double tap-and-hold the button for the scrolling to resume. Restarting the application restores the phone-like scrolling functionality. I am wondering if anyone else has seen this or figured it out - try it with your apps and see if it is the case as well. I modified the snippet above so that you can start a new project, copy and paste this into form1's code, and hit run.
Public Class Form1
Dim FlowPanel As New FlowLayoutPanel
Private Function GenerateButton(ByVal pName As String) As Button
Dim mResult As New Button
With mResult
.Name = pName
.Text = pName
.Width = 128
.Height = 128
.Margin = New Padding(0)
.Padding = New Padding(0)
.BackColor = Color.CornflowerBlue
AddHandler .MouseDown, AddressOf Button_MouseDown
AddHandler .MouseMove, AddressOf Button_MouseMove
End With
Return mResult
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
Me.Width = 806
Me.Height = 480
FlowPanel.Padding = New Padding(0)
FlowPanel.Margin = New Padding(0)
' FlowPanel.ColumnCount = Me.Width / (128 + 6)
FlowPanel.Dock = DockStyle.Fill
FlowPanel.AutoScroll = True
Me.Controls.Add(FlowPanel)
Dim i As Integer
For i = 1 To 98
FlowPanel.Controls.Add(GenerateButton("btn" & i.ToString))
Next
End Sub
Dim myMouseDownPoint As Point
Dim myCurrAutoSMouseDown As Point
Private Sub Button_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
myMouseDownPoint = PointToClient(Cursor.Position)
myCurrAutoSMouseDown = FlowPanel.AutoScrollPosition
End Sub
Private Sub Button_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim mLocation As Point = PointToClient(Cursor.Position)
If myMouseDownPoint <> mLocation Then
Dim mCurrAutoS As Point
Dim mDeslocation As Point = myMouseDownPoint - mLocation
mCurrAutoS.X = Math.Abs(myCurrAutoSMouseDown.X) + mDeslocation.X
mCurrAutoS.Y = Math.Abs(myCurrAutoSMouseDown.Y) + mDeslocation.Y
FlowPanel.AutoScrollPosition = mCurrAutoS
End If
End If
End Sub
End Class
Thanks for the code , I made ​​some changes to improve behavior . I hope it can be useful to someone .
Dim myMouseDownPoint As Point
Dim myCurrAutoSMouseDown As Point
'Add boolean variable a true.
Private _ValidateClickEvent As Boolean = True
Private Sub MyMouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
myMouseDownPoint = PointToClient(Cursor.Position)
myCurrAutoSMouseDown = Panel1.AutoScrollPosition
End Sub
' Add MouseUp event for return the boolean variable a true.
Private Sub MyMouseUp(ByVal sender As Object, ByVal e As MouseEventArgs)
_ValidateClickEvent = True
End Sub
'Set boolean variable a false when change mlocation.
Private Sub MyMouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
If e.Button = Windows.Forms.MouseButtons.Left Then
Dim mLocation As Point = PointToClient(Cursor.Position)
If myMouseDownPoint <> mLocation Then
Dim mCurrAutoS As Point
Dim mDeslocation As Point = CType(myMouseDownPoint - mLocation, Size)
mCurrAutoS.X = Math.Abs(myCurrAutoSMouseDown.X) + mDeslocation.X
mCurrAutoS.Y = Math.Abs(myCurrAutoSMouseDown.Y) + mDeslocation.Y
Panel1.AutoScrollPosition = mCurrAutoS
_ValidateClickEvent = False
End If
End If
End Sub
' Test boolean variable to perform click event.
Private Sub MyClick(sender As System.Object, e As System.EventArgs)
If _ValidateClickEvent Then
........................
Else
_ValidateClickEvent = True
End If
End Sub

Datagridview_cellvaluechanged only updates on second try

DirtyStateChanged lets me commit immediately when I click the checkbox
Private Sub dataGridView4_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DataGridView4.CurrentCellDirtyStateChanged
If DataGridView4.IsCurrentCellDirty Then
DataGridView4.CommitEdit(DataGridViewDataErrorContexts.Commit)
End If
End Sub
Private Sub DataGridView4_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView4.CellValueChanged
For c As Integer = 2 To DataGridView4.ColumnCount - 1
If DataGridView4.Rows(e.RowIndex).Cells(c).Value = True Then
'Disable this persons' row on datagridview5
Dim aName As String = DataGridView4.Rows(e.RowIndex).Cells(0).Value
For Each dRow As DataGridViewRow In DataGridView6.Rows
If dRow.Cells(0).FormattedValue = aName Then
dRow.ReadOnly = True
For Each cell As DataGridViewCell In dRow.Cells
dRow.Cells(cell.ColumnIndex).Style.BackColor = Color.LightGray
Next
'DataGridView6.Update()
End If
Next
End If
Next
End Sub
When I click a checkbox on datagridview3, it should update the row on datagridview5 with a new backcolor and readOnly.
What seems to happen is it does not seem to work the first time clicking the checkbox. It does work perfectly on the second try though.
How can I make it validate on the first try?

Change row font on datagridview on mouse over, vb.net

I want to get underline font on datagridview row when mouse is over a row no matter which row is selected.
I get that - a half :)
Private Sub aDgv_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles aDgv.MouseMove
Dim hit As DataGridView.HitTestInfo = aDgv.HitTest(e.X, e.Y)
If hit.Type = DataGridViewHitTestType.Cell Then
aDgv.Rows(hit.RowIndex).DefaultCellStyle.Font = New Font(aDgv.DefaultCellStyle.Font, FontStyle.Underline)
End If
End Sub
So, when I come over row text in that row becomes underlined (as expected), when I move to next row then those next row becomes underlined but previously don't back to normal font.
What to do that only text in row on which is mouseover become underlined.
How to reset font to normal when mouse goes to other row?
To back the normal Font just use the CellMouseLeave event
Private Sub DataGridView1_MouseMove(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseMove
Dim normalFont = New Font(DataGridView1.DefaultCellStyle.Font, FontStyle.Regular)
Dim hit As DataGridView.HitTestInfo = DataGridView1.HitTest(e.X, e.Y)
If hit.Type = DataGridViewHitTestType.Cell Then
If DataGridView1.Rows(hit.RowIndex).Cells(hit.ColumnIndex).FormattedValue.ToString().Trim().Length > 0 Then
DataGridView1.Rows(hit.RowIndex).DefaultCellStyle.Font = New Font(DataGridView1.DefaultCellStyle.Font, FontStyle.Underline)
Else
DataGridView1.Rows(hit.RowIndex).DefaultCellStyle.Font = normalFont
End If
End If
End Sub
Private Sub DataGridView1_CellMouseLeave(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellMouseLeave
Dim normalFont = New Font(DataGridView1.DefaultCellStyle.Font, FontStyle.Regular)
If (e.ColumnIndex > -1) Then
If e.RowIndex > -1 Then
If DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).FormattedValue.ToString().Trim().Length > 0 Then
DataGridView1.Rows(e.RowIndex).DefaultCellStyle.Font = normalFont
Else
DataGridView1.Rows(e.RowIndex).DefaultCellStyle.Font = normalFont
End If
End If
End If
End Sub

Drag data from DG and other controls to another DG in vb.net

I have form in VB.Net 2010:
I want to click-drag multi rows in dgRegister and Date, Course ID to drop in dgCourseStudent with column Date, Register ID, Register Name and Course ID.
How to code this in vb.net language?
First of all put the AllowDrop property of dgCourseStudent to True (it will accept the dragging events). I've presumed you're using DataSet or DataTable, here my example:
Dim downHitInfo As DataGridView.HitTestInfo = Nothing 'Used to keep trace of dragging info
''MouseDown used to know is a DragDrop event is required
Private Sub dgRegister_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgRegister.MouseDown
Dim view As DataGridView = CType(sender, DataGridView)
Dim hitInfo As DataGridView.HitTestInfo = view.HitTest(e.X, e.Y)
If Not Control.ModifierKeys = Keys.None Then
Exit Sub
End If
If e.Button = MouseButtons.Left And hitInfo.RowIndex >= 0 Then
downHitInfo = hitInfo
End If
End Sub
''MouseMove used to know what DataRow is being dragged.
Private Sub dgRegister_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgRegister.MouseMove
Dim view As DataGridView = CType(sender, DataGridView)
If e.Button = MouseButtons.Left And Not downHitInfo Is Nothing Then
Dim dragSize As Size = SystemInformation.DragSize
Dim DragRect As Rectangle = New Rectangle(New Point(Convert.ToInt32(downHitInfo.ColumnX - dragSize.Width / 2), _
Convert.ToInt32(downHitInfo.RowY - dragSize.Height / 2)), dragSize)
If Not DragRect.Contains(New Point(e.X, e.Y)) Then
'Extract the DataRow
Dim gridRowView As DataGridViewRow = DirectCast(view.Rows(downHitInfo.RowIndex), DataGridViewRow)
Dim rowView As DataRowView = DirectCast(gridRowView.DataBoundItem, DataRowView)
'Raise the DragDrop with the extracted DataRow
view.DoDragDrop(rowView.Row, DragDropEffects.Move)
downHitInfo = Nothing
End If
End If
End Sub
'' For mouse cursor
Private Sub dgCourseStudent_DragOver(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles dgCourseStudent.DragOver
e.Effect = DragDropEffects.Move
End Sub
''The core of draggin procedure
Private Sub dgCourseStudent_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles dgCourseStudent.DragDrop
'Retreive the dragged DataRow
Dim draggedRow As DataRow = CType(e.Data.GetData(GetType(DataRow)), DataRow)
''
'' Put your code here to insert the dragged row into dgCourseStudent grid
End Sub