تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[كود] عمل DragDrop Row in DGV
#2
كود رائع جدا  ،،، لكن واجهتني بعض المشاكل منها اذا قمت برمي السطر خارج القريد الفيو فان السهم الاصفر لا يختفي ،، ثانيا مع ظهور الحقل الاضافي الااخير في حالة تفعيل امكانية الاضافة في القريد فيو فانها تظهر اخطأ  ،  ايضا مؤشر السهم لا يتناسب مع حركت الفأره  فانه يشير الى صف غير صحيح   ،،  على العموم قمت بالبحث بالانترنت  ،،  ووجدت هذه الاكواد  و عدلتها لكي يمكن  اضافتها بمودل :


PHP كود :
 #Region "GridView DragDrop"


    Private fromIndex As Integer
    
Private dragIndex As Integer
    
Private dragRect As Rectangle


    
Public Sub Dragable(ByVal DGV As DataGridView)
        DGV.AllowDrop True
        AddHandler DGV
.DragOverAddressOf DGVDragOver
        AddHandler DGV
.MouseDownAddressOf DGVMouseDown
        AddHandler DGV
.DragDropAddressOf DGVDragDrop
        AddHandler DGV
.MouseMoveAddressOf DGVMouseMove
    End Sub

    
Private Sub DGVDragDrop(ByVal sender As ObjectByVal e As DragEventArgs)
        Dim p As Point sender.PointToClient(New Point(e.Xe.Y))
        dragIndex sender.HitTest(p.Xp.Y).RowIndex
        
If (e.Effect DragDropEffects.MoveThen
            Dim dragRow 
As DataGridViewRow e.Data.GetData(GetType(DataGridViewRow))
            Dim DGVLastRowIndex As Integer sender.rows.count 1
            
Try
                If dragIndex <> -1 AndAlso Not dragIndex DGVLastRowIndex AndAlso Not dragRow.Index DGVLastRowIndex AndAlso Not dragRow.Index dragIndex Then
                    sender
.Rows.RemoveAt(fromIndex)
                    sender.Rows.Insert(dragIndexdragRow)
                    sender.Rows(dragIndex).Selected True
                    sender
.CurrentCell sender.Rows(dragIndex).Cells(0)
                End If

            Catch ex As Exception

            End 
Try
        End If
    End Sub

    
Private Sub DGVDragOver(ByVal sender As ObjectByVal e As DragEventArgs)
        e.Effect DragDropEffects.Move
    End Sub

    
Private Sub DGVMouseDown(ByVal sender As ObjectByVal e As MouseEventArgs)
        fromIndex sender.HitTest(e.Xe.Y).RowIndex
        
If fromIndex > -1 Then
            Dim dragSize 
As Size SystemInformation.DragSize
            dragRect 
= New Rectangle(New Point(e.- (dragSize.Width 2), _
                                               e
.- (dragSize.Height 2)), _
                                     dragSize
)
        Else
            dragRect Rectangle.Empty
        End If
    End Sub

    
Private Sub DGVMouseMove(ByVal sender As ObjectByVal e As MouseEventArgs)
        If (e.Button And MouseButtons.Left) = MouseButtons.Left Then
            
If (dragRect <> Rectangle.Empty AndAlso Not dragRect.Contains(e.Xe.Y)) Then
                sender
.DoDragDrop(sender.Rows(fromIndex), DragDropEffects.Move)
            End If
        End If
    End Sub

#End Region 
الرد }}}
تم الشكر بواسطة: HASAN6.0 , asemshahen5


الردود في هذا الموضوع
عمل DragDrop Row in DGV - بواسطة HASAN6.0 - 04-12-15, 12:23 AM
RE: عمل DragDrop Row in DGV - بواسطة myalsailamy - 04-12-15, 04:29 AM

التنقل السريع :


يقوم بقرائة الموضوع: