TaskBoard Card Index Location

2 Answers 251 Views
TaskBoard
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
Martin Hamilton asked on 07 Oct 2021, 04:23 PM
When I move a TaskBoard card up or down within a TaskBoard Column, how do I get the Index location for the card that was moved?
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 07 Oct 2021, 04:49 PM

Also, is there an event for TaskBoardColumnCardIndexChanging/Changed ????
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 07 Oct 2021, 05:07 PM

If I get that from the DragDrop Service how do I get the drop location?

    Private Sub TaskBoardCardDragDropService_PreviewDragDrop(sender As Object, e As RadDropEventArgs)
        Dim draggedItem As RadTaskCardElement = TryCast(e.DragInstance, RadTaskCardElement)
        Dim rowElement As RadTaskBoardColumnElement = TryCast(e.HitTarget, RadTaskBoardColumnElement)
        Dim tableElement As RadTaskBoardColumnElement = TryCast(e.HitTarget, RadTaskBoardColumnElement)
        If rowElement Is Nothing AndAlso tableElement Is Nothing Then
            Return
        End If
        e.Handled = True
        Dim CardID As Integer = draggedItem.Tag
        Dim ColumnID As Integer = rowElement.Tag
    End Sub

 

Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 07 Oct 2021, 05:09 PM

The code above is not perfect, but i tried as best as I could for the moment pending your response.
Perhaps you can fix any mistakes that I made when you provide the answer??? Please.

2 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 12 Oct 2021, 08:27 AM
Hello, Martin, 

Indeed, using the RadTaskBoardDragDropService is the suitable approach to handle the task card moving action. Note that in the PreviewDragDrop event you have access to the DropLocation in the event arguments. However, you have also access to the HitTarget. It can be either a RadTaskBoardColumnElement or a RadTaskCardElement. But in both cases you can compare the dragged task card's column and the target column and conclude whether the column is changed: 
        AddHandler Me.RadTaskBoard1.TaskBoardElement.DragDropService.PreviewDragDrop, AddressOf radTaskBoard1_PreviewDragDrop 
         
    End Sub

    Private Sub radTaskBoard1_PreviewDragDrop(sender As Object, e As Telerik.WinControls.RadDropEventArgs)
        Dim draggedItem As RadTaskCardElement = TryCast(e.DragInstance, RadTaskCardElement) 
        Dim targetColumnElement As RadTaskBoardColumnElement = TryCast(e.HitTarget, RadTaskBoardColumnElement)
        Dim targetCardElement As RadTaskCardElement = TryCast(e.HitTarget, RadTaskCardElement) 
        If draggedItem Is Nothing AndAlso targetCardElement Is Nothing AndAlso targetColumnElement Is Nothing Then
            Return
        End If
        e.Handled = True
        If targetColumnElement Is Nothing Then
            targetColumnElement = targetCardElement.FindAncestor(Of RadTaskBoardColumnElement)()
        End If
        Dim draggedItemColumnElement As RadTaskBoardColumnElement = draggedItem.FindAncestor(Of RadTaskBoardColumnElement)()
        If Not draggedItemColumnElement.Equals(targetColumnElement) Then
            ' moved to another column
        End If
         
        Dim CardID As Integer = draggedItem.Tag
        Dim ColumnID As Integer = targetColumnElement.Tag
    End Sub
Each RadTaskBoardColumnElement offers the TaskCardCollection where all task cards for this column are stored. You can determine the card's index by using the TaskCardCollection.IndexOf method passing the respective task. 

I hope this information helps. If you need any further assistance please don't hesitate to contact me.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Remote troubleshooting is now easier with Telerik Fiddler Jam. Get the full context to end-users' issues in just three steps! Start your trial here - https://www.telerik.com/fiddler-jam.
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 12 Oct 2021, 11:16 AM

Dess, Thank you for your help on this matter... everything works great except for the IndexOf part

Below, I provide the Database Schema for the table I'm trying to update as well as the SQL for that Update.
The problem is that IndexOf always returns -1 at the drop stage.
Is there another method that I'm not understanding here?
Hopefully you can help me address this.

 

    Private Sub radTaskBoard1_PreviewDragDrop(sender As Object, e As Telerik.WinControls.RadDropEventArgs)
        Dim SQL As String = ""
        Dim draggedItem As RadTaskCardElement = TryCast(e.DragInstance, RadTaskCardElement)
        Dim targetColumnElement As RadTaskBoardColumnElement = TryCast(e.HitTarget, RadTaskBoardColumnElement)
        Dim targetCardElement As RadTaskCardElement = TryCast(e.HitTarget, RadTaskCardElement)
        If draggedItem Is Nothing AndAlso targetCardElement Is Nothing AndAlso targetColumnElement Is Nothing Then
            Return
        End If
        e.Handled = True
        Dim CardID As Integer = draggedItem.Tag  'The TaskBoardCards.id of the dragged card
        Dim ColumnID As Integer = targetColumnElement.Tag  'The TaskBoardColumnElements.id of the target column
        If targetColumnElement Is Nothing Then
            targetColumnElement = targetCardElement.FindAncestor(Of RadTaskBoardColumnElement)()
        End If
        Dim draggedItemColumnElement As RadTaskBoardColumnElement = draggedItem.FindAncestor(Of RadTaskBoardColumnElement)()
        If Not draggedItemColumnElement.Equals(targetColumnElement) Then
            ' moved to another column

            'Database Schema
            'Select Top(1000) [id]
            '    ,[TaskBoardColumnElementID]
            '    ,[TaskBoardCardID]
            '    ,[TaskBoardCardSequence]
            'From [TaskBoard].[dbo].[TaskBoardCardsToColumnElement]

            'Execute the SQL to update the database table
            SQL = $"UPDATE TaskBoardCardsToColumnElement SET TaskBoardColumnElementID = {targetColumnElement.Tag} WHERE TaskBoardCardID = {CardID}"
            'I think that because the dropped card has not yet been recognized as being 'dropped'
            'that the indexof doesn't tell me the position (indexof) the drop location at this point
            'it always returns -1
            Dim TaskBoardCardSequence As Integer = targetColumnElement.TaskCardCollection.IndexOf(draggedItem)
            MsgBox(TaskBoardCardSequence)
            'The SQL I'd like to execute
            SQL = $"UPDATE TaskBoardCardsToColumnElement SET TaskBoardColumnElementID = {targetColumnElement.Tag}, TaskBoardCardSequence = {TaskBoardCardSequence} WHERE TaskBoardCardID = {CardID}"
        End If
    End Sub
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 12 Oct 2021, 12:07 PM

For now, I'm doing this - but it means the user has to click a Save Button instead of the changes being saved automatically via some Event.

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
        Dim SQL As String = ""
        Dim oSQL As New DAL.SqlServer With {.ConnectionString = _cnTaskBoard}

        'the columns are dynamically created from the database table
        'the PKID from the database table is placed into the tag property 
        'of the column

        For i = 0 To RadTaskBoard1.Columns.Count - 1
            Dim TaskBoardColumnElementID As Integer = i
            Dim oRadColumn As RadTaskBoardColumnElement = RadTaskBoard1.TaskBoardElement.Columns(i)

            'iterate the cards that are in the column
            'the index position will be needed to update the database TaskBoardCardsToColumnElement table
            'so that when the cards are loaded to the column they are in the right sequence
            Dim CardIndexPosition As Integer = 1
            For Each oRadTaskCardElement As RadTaskCardElement In oRadColumn.TaskCardCollection
                Dim TaskBoardColumnID As Integer = oRadColumn.Tag
                SQL = $"Update TaskBoardColumnElements SET Collapsed = {IIf(oRadColumn.IsCollapsed, 1, 0)} WHERE id = {TaskBoardColumnID}"
                oSQL.ExecuteNonQuery(SQL)

                Dim TaskBoardCardID As Integer = oRadTaskCardElement.Tag
                SQL = $"Update TaskBoardCardsToColumnElement SET TaskBoardCardSequence = {CardIndexPosition}, TaskBoardColumnElementID = {oRadColumn.Tag} WHERE TaskBoardCardID = {TaskBoardCardID}"
                oSQL.ExecuteNonQuery(SQL)
                CardIndexPosition += 1
            Next
        Next
        LoadTaskBoard()
    End Sub
Dess | Tech Support Engineer, Principal
Telerik team
commented on 14 Oct 2021, 10:15 AM

Hello, Martin,

The PreviewDragDrop event allows you to get a handle on all the aspects of the drag and drop operation, the source (drag) control/element, the destination (target) control/element, as well as the task card being dragged. This is where we will initiate the actual physical move of the task(s) from one column to the target column or from one RadTaskBoard to another. 

It is expected to get -1 as an index if the task card is not a part of the target column yet. You can check whether the column's TaskCardCollection contains the dragged card, but I believe it doesn't since the returned index is -1. If the Handled argument is set to true, this means that you are managing the drop operation and in order to get a valid index, you need to insert the dragged task to the target column first if it is coming from another column. Then, you can get the index and proceed further with saving the changes to the database.
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 14 Oct 2021, 03:59 PM

Hi Dess, thank you for the explanation but I'm not quite sure I understand what you are saying.

So, do I set e.Handled to equal False?

We might be talking about 2 different scenarios here
Scenario 1) Moving a card within the same column
Since there is no TaskCardMoved Event - I still cannot get a valid index from the TaskBoardCardDragDropService_PreviewDragDrop() routine.
So, for example; if I have 2 cards [CardA and CardB] in Column(0) and I move CardA to the position below CardB - in the TaskBoardCardDragDropService_PreviewDragDrop  - CardA still gives me IndexOf = 0

Scenario 2) Moving a CardA from Column(0) to Column(1)
In this scenario - Let's pretend that Column(1) already has 2 cards in it... CardC and CardD... and I want to move CardA from Column(0) to Column(1) and drop it between CardC and CardD... so it would look like this in Column(0).
CardC then CardA then CardD - in that sequence.

I know you've done it before for other such examples but would it be possible for you to create a small vbDemo app so that I can see how this is done for both Scenarios?  That would probably be faster than attempting to go back and forth via the forum comments.  If that would be possible it would be Greatly Appreciated.


Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 14 Oct 2021, 04:04 PM

Sorry, I should have made this more clear with text formatting

We might be talking about 2 different scenarios here
Scenario 1) Moving a card within the same column
Since there is no TaskCardMoved Event - I still cannot get a valid index from the TaskBoardCardDragDropService_PreviewDragDrop() routine.
So, for example; if I have 2 cards [CardA and CardB] in Column(0) and I move CardA to the position below CardB - in the TaskBoardCardDragDropService_PreviewDragDrop  - CardA still gives me IndexOf = 0

Scenario 2) Moving a CardA from Column(0) to Column(1)
In this scenario - Let's pretend that Column(1) already has 2 cards in it... CardC and CardD... and I want to move CardA from Column(0) to Column(1) and drop it between CardC and CardD... so it would look like this in Column(0).
CardC then CardA then CardD - in that sequence.

I know you've done it before for other such examples but would it be possible for you to create a small vbDemo app so that I can see how this is done for both Scenarios?  That would probably be faster than attempting to go back and forth via the forum comments.  If that would be possible it would be Greatly Appreciated.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 Oct 2021, 09:25 AM
Hello, Martin,

When you set the Handled argument to true, this means that the default drop logic wouldn't be performed and you intend to implement such. Hence, in this case you need to remove the task card from the source column and insert it on the target column. If you want the default logic to be performed, leave the Handled argument to false in the PreviewDragDrop event.

The PreviewDragDrop event gives you the state of the dragged task and target location before the drop logic is actually executed. If you want to just to get the index of the affected task card after the drop operation, you can use the following code snippet that I prepared for handling this case: 
 Me.RadTaskBoard1.TaskBoardElement.DragDropService = New CustomRadTaskBoardDragDropService(Me.RadTaskBoard1.TaskBoardElement)
    Public Class CustomRadTaskBoardDragDropService
        Inherits RadTaskBoardDragDropService

        Dim ownerTaskBoardElement As RadTaskBoardElement
        Public Sub New(owner As RadTaskBoardElement)
            MyBase.New(owner)
            ownerTaskBoardElement = owner
        End Sub

        Protected Overrides Sub OnPreviewDragDrop(e As Telerik.WinControls.RadDropEventArgs)

            Dim draggedItem As RadTaskCardElement = TryCast(e.DragInstance, RadTaskCardElement)
            Dim targetColumnElement As RadTaskBoardColumnElement = TryCast(e.HitTarget, RadTaskBoardColumnElement)
            Dim targetCardElement As RadTaskCardElement = TryCast(e.HitTarget, RadTaskCardElement)
            If draggedItem Is Nothing AndAlso targetCardElement Is Nothing AndAlso targetColumnElement Is Nothing Then
                Return
            End If
            If targetColumnElement Is Nothing Then
                targetColumnElement = targetCardElement.FindAncestor(Of RadTaskBoardColumnElement)()
            End If
            Dim draggedItemColumnElement As RadTaskBoardColumnElement = draggedItem.FindAncestor(Of RadTaskBoardColumnElement)()
            If Not draggedItemColumnElement.Equals(targetColumnElement) Then
                ' moved to another column
                Console.WriteLine("moved to another column")
                Console.WriteLine(" column before the drop operation: " & ownerTaskBoardElement.Columns.IndexOf(draggedItemColumnElement))
                Console.WriteLine(" column after the drop operation: " & ownerTaskBoardElement.Columns.IndexOf(targetColumnElement))
            End If

            MyBase.OnPreviewDragDrop(e) ' perform the base logic

            Dim index = targetColumnElement.TaskCardCollection.IndexOf(draggedItem)

        End Sub

    End Class

I believe that it would help you for achieving your goal.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 18 Oct 2021, 04:10 PM

Dess,  This is Excellent and exactly what I was looking for.

I really appreciate your answering this question with the code above.  It's Perfect !!!

Thank You Very Much

Tags
TaskBoard
Asked by
Martin Hamilton
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or