Solved

VB,DataGridView,Drag and Drop,Reordering of rows

Posted on 2009-04-13
2
1,401 Views
Last Modified: 2013-11-25
I would llike to use drag  drop to reorder the students. (see sample Jpg file attached)
The studentNo field is the same as the row index plus 1, and the fill query for the DataGridView is
sorted by StudentNo, so the code just has to change the studentNo appropriately.
The best I can come up with so far is a button which lifts the selected row by one row.
(Similarly I can add a down button to do the reverse)
Repeated clickng of this button achieves the desired result but is not very user friendly.
Also I think the code (atached) is messy.
For drag and drop, I was looking for a mouse down event and Mouse up event to tell me the "from row" and the "to row" but the CurrentCell.RowIndex.Value is always a value behind
because the selected row does not change until after the mouse up event occurs.
Any ideas would be appreciated.
Private Sub ButMoveUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButMoveUp.Click
        Dim JPCurrentRow As Int16 = CShort(EntriesDGV.CurrentRow.Index)
 
        If JPCurrentRow > 0 Then
            'Get Parameter in preparation for re-fill
            Dim ParmExamCode As String
            ParmExamCode = CStr(AvailExamsDGV.Item("AeDgvExamCode", AvailExamsDGV.CurrentCell.RowIndex).Value)
            ' Swap order one row
            Dim JPCurrentRowID As Int32 = CInt(EntriesDGV.Item("EntryID", JPCurrentRow).Value)
            Dim JPToRowID As Int32 = CInt(EntriesDGV.Item("EntryID", JPCurrentRow - 1).Value)
 
            Me.EntriesTableAdapter.QryUpdateStudentNo(JPCurrentRow, JPCurrentRowID)
            Me.EntriesTableAdapter.QryUpdateStudentNo(JPCurrentRow + CShort(1), JPToRowID)
            'EntriesDGV.Item("StudentNo", JPToRow).Value = JPToRow - 1
            'EntriesDGV.Item("StudentNo", JPToRow - 1).Value = JPToRow
            'Re-fill DataGrid view
            Me.EntriesTableAdapter.Fill(Me.ExamPlannerUserFileDataSet.Entries, ParmExamCode)
        Else
            MsgBox("Already on first Row")
        End If
 
    End Sub

Open in new window

DataGridView.jpg
0
Comment
Question by:Polyview
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 24135291
Custom Row and Column Drag and Drop Reordering Operations with the DataGridView
http://www.danielsoper.com/programming/DataGridViewDragDropRowsColumns.aspx
0
 
LVL 1

Expert Comment

by:surfbored
ID: 24304708
Does anyone have VB code for this same solution? The given link uses C#.

TIA.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month7 days, 11 hours left to enroll

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question