VBiB/ACCB.net - Visual Basic in België | .net Ineta User Group  
Hoofdmenu

Advertenties

Het Computer Winkeltje HCW


Evenementen

Komende evenementen

Tue, 30 March 2010
Wed, 31 March 2010
Thu, 01 April 2010
Wed, 07 April 2010
Wed, 05 May 2010

Forum

Plaats nieuw bericht   Plaats Reactie
Vorige onderwerp Printervriendelijke versie Log in om je privé berichten te bekijken Volgende onderwerp
Auteur Bericht
bomentOffline
Onderwerp: Datagridview move row with drag and drop  BerichtGeplaatst: 17 sep 2009 - 20:53
In de startblokken


Geregistreerd op: 10-feb-2009
Berichten: 30

Status: Offline
Wie kan me op weg helpen met een datagrid view, waarbij ik een row van plaats kan veranderen met drag en drop.
Dus regel "verwijderen" en ergens anders tussen plaatsen.
ik heb al van alles gevonden op internet het laatste was met buttons "Top, Up, Down en Bottom" vind ik niet zo gebruiks vriendelijk ik zou het mooier vinden met drag en drop.

Alvast bedankt,
 
 Bekijk gebruikers profiel Stuur privé bericht Bekijk de homepage  
Reageer met quote Naar boven
SvekkeOffline
Onderwerp: Re: Datagridview move row with drag and drop  BerichtGeplaatst: 18 sep 2009 - 09:18
Op dreef


Geregistreerd op: 01-mei-2007
Berichten: 160
Woonplaats: Herselt
Status: Offline
Hier misschien eens kijken?

http://www.codeplex.com/dragdropgrid
 
 Bekijk gebruikers profiel Stuur privé bericht  
Reageer met quote Naar boven
bomentOffline
Onderwerp: Re: Datagridview move row with drag and drop  BerichtGeplaatst: 19 sep 2009 - 12:21
In de startblokken


Geregistreerd op: 10-feb-2009
Berichten: 30

Status: Offline
Ik heb daar gekeken en de dll gedownload.
In eerste instanstie werkt het best goed, maar voor mijn doel zit er waarschijnlijk een bug in.
Ik pas het toe in 1 datgridview, voor het verplaatsen van regels.
Ik heb gekozen bij de instellingen optie voor "move" dit moet inhouden , de regel verplaatsen dus cut en insert(paste).
Het is merkwaardig dat van boven uit, dus "top down" het prachtig werkt, maar van onder "botom up" werkt het niet , hij laat de "bron" regel staan en kopieerd over de "doel" regel, wat inhoud dat men twee dezelfde regels overhoud . op de oude plaats en op de nieuwe plaats. en er is een regel verdwenen.

Ik heb de broncode van deze dll ook , ik zal deze eens bestuderen waar dit fout gaat.
 
 Bekijk gebruikers profiel Stuur privé bericht Bekijk de homepage  
Reageer met quote Naar boven
SvekkeOffline
Onderwerp: Re: Datagridview move row with drag and drop  BerichtGeplaatst: 19 sep 2009 - 18:24
Op dreef


Geregistreerd op: 01-mei-2007
Berichten: 160
Woonplaats: Herselt
Status: Offline
Ja heb het zelf niet getest, maar was het wel tegengekomen.
Mja je bent een echte programmeur he Smile Dus zal het wel geen probleem zijn om de fout te vinden.
 
 Bekijk gebruikers profiel Stuur privé bericht  
Reageer met quote Naar boven
bomentOffline
Onderwerp: Re: Datagridview move row with drag and drop  BerichtGeplaatst: 20 sep 2009 - 07:53
In de startblokken


Geregistreerd op: 10-feb-2009
Berichten: 30

Status: Offline
Ik plaats toch even de broncode, misschien is er iemand die de fout ziet.
Het zou kunnen wezen dat het ontwikkeld is in VB2002 en ik gebruik het in 2008.
het zal waarschijnlijk fout gaan met de regelnumering setting.
Iemand ???

Visual Basic code:
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Data
Imports System.Text
Imports System.Windows.Forms

' ||*****************************************************************************************************************************||
'   Title  : DragDropGrid
'   Author : Thomas B. Holland
'   Date   : 01/03/08
'   
'   The base code for this control was taken from the article "How Do I Perform A Drag And Drop Reorder Of Rows?" on
'   WindowsClient.net.  The author is not stated in the article.
'
'   The DragDropGrid enables Drag And Drop functionality between 2 DataGridViews without having to write any code.  The new control
'   exposes two new properties that will appear under "Misc" section in the properties window.  They are AllowDrag and AllowReorder.
'   
'   The AllowDrag property sets the ability to drag and item from the control.  If you do not set this property, attempting to drag
'   will simply highlight rows as you drag over them.
'
'   The AllowReorder property lets the control know that it is ok for items to be reordered within the same control.
'
'   It is possible to drag between two or more DragDropGrids and also reorder within the same DragDropGrid.
'
'   Only 1 item can be moved at a time.  Moving of a selection of multiple items is not supported.
' ||*******************************************************************************************************************************||

Namespace Controls
    Public Class DragDropGrid
        Inherits DataGridView

        'Constructor
        Public Sub New()
            dt = Nothing
        End Sub

        Private dragBoxFromMouseDown As Rectangle
        Private isDragging As Boolean = False
        Private ds As New DataSet
        Private bs As New BindingSource
        Public dt As New DataTable
        Public rowIndexFromMouseDown As Int32 = 0
        Public rowIndexOfItemUnderMouseToDrop As Int32 = 0

#Region "CustomProperties"

        Private _AllowReorder As Boolean = False
        Private _AllowDrag As Boolean = False
        Private _DragType As enumDragType

        Public Property AllowDrag() As Boolean

            Get
                Return _AllowDrag
            End Get
            Set(ByVal value As Boolean)
                _AllowDrag = value
            End Set

        End Property

        Public Property AllowReorder() As Boolean

            Get
                Return _AllowReorder
            End Get
            Set(ByVal value As Boolean)
                _AllowReorder = value
            End Set

        End Property

        Public Enum enumDragType
            Move
            Copy
        End Enum

        Public Property DragType() As enumDragType
            Get
                Return _DragType
            End Get
            Set(ByVal value As enumDragType)
                _DragType = value
            End Set
        End Property


#End Region

#Region "EventOverrides"

        Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)

            If AllowDrag Then

                'Get the index of the item the mouse is below.
                rowIndexFromMouseDown = Me.HitTest(e.X, e.Y).RowIndex

                If (Not rowIndexFromMouseDown = -1) Then
                    ' Remember the point where the mouse down occurred.
                    ' The DragSize indicates the size that the mouse can move
                    ' before a drag event should be started.               
                    Dim dragSize As Size = SystemInformation.DragSize
                    ' Create a rectangle using the DragSize, with the mouse position being
                    ' at the center of the rectangle.
                    dragBoxFromMouseDown = New Rectangle(New Point(CType(e.X - (dragSize.Width / 2), Int32), _
                    CType(e.Y - (dragSize.Height / 2), Int32)), dragSize)
                Else
                    ' Reset the rectangle if the mouse is not over an item in the ListBox.
                    dragBoxFromMouseDown = Rectangle.Empty
                End If
            End If
            MyBase.OnMouseDown(e)
        End Sub

        Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)

            If (e.Button And MouseButtons.Left) = MouseButtons.Left Then

                ' If the mouse moves outside the rectangle, start the drag.
                If Not dragBoxFromMouseDown = Rectangle.Empty And _
                    Not dragBoxFromMouseDown.Contains(e.X, e.Y) Then

                    ' Proceed with the drag and drop, passing in the list item.                   
                    Dim dropEffect As DragDropEffects = Me.DoDragDrop( _
                    Me.Rows(Me.rowIndexFromMouseDown), _
                    DragDropEffects.Move)
                    Me.isDragging = True
                End If

            End If

            MyBase.OnMouseMove(e)

        End Sub

        Protected Overrides Sub OnDataBindingComplete(ByVal e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs)

            Try
                If Me.DataSource.GetType Is GetType(BindingSource) Then
                    bs = CType(Me.DataSource, BindingSource)
                    ds = CType(Me.bs.DataSource, DataSet)
                    dt = ds.Tables(0)
                ElseIf Me.DataSource.GetType Is GetType(DataSet) Then
                    ds = CType(Me.DataSource, DataSet)
                    dt = ds.Tables(0)
                Else
                    dt = Nothing
                End If

            Catch ex As Exception

            End Try

            MyBase.OnDataBindingComplete(e)

        End Sub

        Protected Overrides Sub OnDragDrop(ByVal e As System.Windows.Forms.DragEventArgs)

            ' The mouse locations are relative to the screen, so they must be
            ' converted to client coordinates.
            Dim clientPoint As Point = Me.PointToClient(New Point(e.X, e.Y))

            ' Get the row index of the item the mouse is below.
            Me.rowIndexOfItemUnderMouseToDrop = _
            Me.HitTest(clientPoint.X, clientPoint.Y).RowIndex

            ' If the drag operation was a move then remove and insert the row.
            If e.Effect = DragDropEffects.Move Then
                Try

                    Dim rowToMove As DataGridViewRow = CType(e.Data.GetData(GetType(DataGridViewRow)), DataGridViewRow)
                    Dim dragInitiator As DragDropGrid = CType(rowToMove.DataGridView, DragDropGrid)
                    Me.rowIndexFromMouseDown = dragInitiator.rowIndexFromMouseDown

                    'If the source grid is bound, then remove the items from the underlying dataset and rebind
                    If dt Is Nothing Then

                        'If its a move, then delete the source item
                        If dragInitiator.DragType = enumDragType.Move Then
                            dragInitiator.Rows.RemoveAt(rowIndexFromMouseDown)
                        Else
                            Dim rowClone As DataGridViewRow
                            rowClone = CType(rowToMove.Clone(), DataGridViewRow)
                            For i As Integer = 0 To rowClone.Cells.Count - 1
                                rowClone.Cells(i).Value = rowToMove.Cells(i).Value
                            Next
                            rowToMove = rowClone
                        End If

                        ' If we are attempting to drop this new row on the datagrid in a spot where the mouse is not over some rows, then we need
                        ' to add it instead of trying to insert it at an index that is out of range.
                        If Me.rowIndexOfItemUnderMouseToDrop > -1 Then
                            Me.Rows.Insert(rowIndexOfItemUnderMouseToDrop, rowToMove)
                        Else : Me.Rows.Add(rowToMove)
                        End If

                        'This control is data bound so modify the underlying data tables
                    Else

                        'get the row data from row before removing and add to new row
                        Dim rowArray As Object() = dragInitiator.dt.Rows(rowIndexFromMouseDown).ItemArray
                        Dim row As DataRow = Me.dt.NewRow()
                        row.ItemArray = rowArray

                        'remove old row and insert new row
                        If Me.rowIndexOfItemUnderMouseToDrop > -1 Then
                            Me.dt.Rows.InsertAt(row, rowIndexOfItemUnderMouseToDrop)
                        Else : dt.Rows.Add(row)
                        End If

                        'If its a move, then delete the source item
                        If dragInitiator.DragType = enumDragType.Move Then dragInitiator.dt.Rows.RemoveAt(rowIndexFromMouseDown)

                    End If

                Catch ex As Exception

                    Throw New Exception(ex.Message)

                End Try


            End If

            Me.isDragging = False
            MyBase.OnDragDrop(e)

        End Sub

        Protected Overrides Sub OnDragOver(ByVal e As System.Windows.Forms.DragEventArgs)

            Dim rowToMove As DataGridViewRow = CType(e.Data.GetData(GetType(DataGridViewRow)), DataGridViewRow)
            Dim gridInitiator As DragDropGrid = CType(rowToMove.DataGridView, DragDropGrid)


            Dim clientPoint As Point = Me.PointToClient(New Point(e.X, e.Y))

            ' Get the row index of the item the mouse is below.
            Me.rowIndexOfItemUnderMouseToDrop = _
            Me.HitTest(clientPoint.X, clientPoint.Y).RowIndex

            Dim row As DataGridViewRow

            ' Reset The Selected property to false so that any row that was selected
            ' and is no longer under the mouse becomes deselected
            For Each row In Me.Rows
                row.Selected = False
            Next

            ' Now set the row underneath the mouse to selected.  This is strictly for asthetic purposes
            If (Me.rowIndexOfItemUnderMouseToDrop > -1) Then Me.Rows(Me.rowIndexOfItemUnderMouseToDrop).Selected = True

            ' If the AllowReorder property is set to True, then allow the drag
            ' If the AllowReorder property is set to False, and the control where the drag began is this, deny the drag
            ' If the AllowReorder property is set to False, and the control where the drag began is NOT this, then allow the drag
            If (AllowReorder) Then
                e.Effect = DragDropEffects.Move
            ElseIf gridInitiator Is Me Then
                e.Effect = DragDropEffects.None
            Else
                e.Effect = DragDropEffects.Move
            End If

            MyBase.OnDragOver(e)

        End Sub

#End Region

    End Class
End Namespace
 
 Bekijk gebruikers profiel Stuur privé bericht Bekijk de homepage  
Reageer met quote Naar boven
bomentOffline
Onderwerp: Re: Datagridview move row with drag and drop  BerichtGeplaatst: 22 sep 2009 - 09:38
In de startblokken


Geregistreerd op: 10-feb-2009
Berichten: 30

Status: Offline
Voor de geintresseerde,
Het werkt alleen zonder koppelin naar database, dus geen DataSource binding, waarom ? ik kan het niet vinden.
Maar zodra je datagridview gevuld wordt d.m.v. Rows.Add werkt alles perfect.
Het is aan te bevelen om de class in je applicatie te plaatsen inplaats van de dll.

suk6, Ben
 
 Bekijk gebruikers profiel Stuur privé bericht Bekijk de homepage  
Reageer met quote Naar boven
YannouOffline
Onderwerp: Re: Datagridview move row with drag and drop  BerichtGeplaatst: 22 sep 2009 - 09:48
Moderator


Geregistreerd op: 14-mrt-2006
Berichten: 2375
Woonplaats: Kraainem
Status: Offline
boment schreef:
Het werkt alleen zonder koppelin naar database, dus geen DataSource binding, waarom ? ik kan het niet vinden.
Ik vermoed dat bij een koppeling naar de database, de gegevens up to date gehouden worden door ze regelmatig opnieuw te laden. Hiermee gaat je aangepast volgorde dan verloren.

Groetjes
 
 Bekijk gebruikers profiel Stuur privé bericht  
Reageer met quote Naar boven
Berichten van afgelopen:     
Ga naar:  
Tijden zijn in GMT + 1 uur
Plaats nieuw bericht   Plaats Reactie
Vorige onderwerp Printervriendelijke versie Log in om je privé berichten te bekijken Volgende onderwerp
PNphpBB2 © 2003-2007 
 

 
Postnuke - ADODB Database - PHP 4/5 - pnPhpBB2 - Hosting bij Openminds
Met dank aan Jürgen voor de jarenlange inzet van visualbasic.be (anno 21-12-2000)
vbib.be gestart op 1/03/06 (extra vanaf 1/09: vbnet.be en vbdotnet.be)
VBiB is gerelateerd met wintips.be

Nieuwsbrief RSS Feed: backend.php