ListControl Drag&Drop with Descritpions

5 posts, 1 answers
  1. Matias
    Matias avatar
    13 posts
    Member since:
    Jan 2013

    Posted 30 Jan 2013 Link to this post

    Hi,

    I'm using the ListBox control with the Scheduler one, so when the user drags an item with description from the ListBox and drops it into the scheduler a new appointment is created. I saw the Demo you provide, however, this one uses plain RadListDataItem and RadListVisualItem. On the description of each item there's a phone number. I have created a new "Add Appointment" form to hold the phone number. My Question is: how can I Drag&Drop ListBox Items with descriptions and retrieve not only the Item text but the description too?

    I've tried the following code, but "item" is always null.
    Private Sub radListBox1_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
        If e.Button <> MouseButtons.Left Then
            Return
        End If
     
        If Me.isDragging Then
            Return
        End If
     
        Dim currentPosition As Point = e.Location
     
        If (Math.Abs(currentPosition.X - Me.mouseDownPosition.X) >= SystemInformation.DragSize.Width) OrElse (Math.Abs(currentPosition.Y - Me.mouseDownPosition.Y) >= SystemInformation.DragSize.Height) Then
            Me.isDragging = True
            Dim dragObject As New DragObject()
            Dim item As DescriptionTextListVisualItem = TryCast(Me.LBox1.ElementTree.GetElementAtPoint(e.Location), DescriptionTextListVisualItem)
     
            If item IsNot Nothing Then
                dragObject.Values.Add(AppointmentFields.Summary, item.Text)
                dragObject.Values.Add(AppointmentFields.Description, item.DescriptionText)
     
                dragObject.Status = AppointmentFields.Summary
     
                TryCast(sender, RadListControl).DoDragDrop(dragObject, DragDropEffects.Copy)
            End If
        End If
    End Sub

    Thank you very much for your time and attention,
    Matias.
  2. Answer
    Peter
    Admin
    Peter avatar
    1148 posts

    Posted 01 Feb 2013 Link to this post

    Hello Matias,

    Thank you for writing.

    The 
    DescriptionTextListVisualItem is a composite element and it contains a few LigthVisualElementsWhen you call GetElementAtPoint method the result is a LigthVisualElement which is nested in the DescriptionTextListVisualItemThe parent of this LightVisualElement is the DescriptionTextListVisualItem and you can get it with the following lines of code:
    Dim radElement As RadElement = Me.RadListControl1.ElementTree.GetElementAtPoint(e.Location)
    If radElement Is Nothing Then Exit Sub
     
    Dim item As DescriptionTextListVisualItem = radElement.FindAncestor(Of DescriptionTextListVisualItem)()
     
    If item IsNot Nothing Then

    I hope this helps.

    Kind regards,
    Peter
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Matias
    Matias avatar
    13 posts
    Member since:
    Jan 2013

    Posted 01 Feb 2013 Link to this post

    Thanks peter for your quick answer.
    The code you provided was pretty helpful and I managed to return the Item Description, however, now I cannot return the Item text

    This is the code as I'm using it now.
    Dim radElement As RadElement = LBox1.ElementTree.GetElementAtPoint(e.Location)
    If radElement Is Nothing Then Exit Sub
     
    Dim item As DescriptionTextListVisualItem = radElement.FindAncestor(Of DescriptionTextListVisualItem)()
     
    If item IsNot Nothing Then
        dragObject.Values.Add(AppointmentFields.Summary, item.Text) 'item.Text returns an empty string.
        dragObject.Values.Add(AppointmentFields.Description, item.DescriptionText)
     
        dragObject.Status = AppointmentFields.Summary
     
        TryCast(sender, RadListControl).DoDragDrop(dragObject, DragDropEffects.Copy)
    End If
    Am I doing something wrong?
    Thank you again!
  5. Matias
    Matias avatar
    13 posts
    Member since:
    Jan 2013

    Posted 01 Feb 2013 Link to this post

    Solved the Item.text issue. The correct way to retrieve that information is Item.Data.text.
    Thanks again for the time spent.
  6. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 06 Feb 2013 Link to this post

    Hello Matias,

    I am happy that you resolved the issue the with the text and I can confirm that this approach is correct.

    Greetings,
    Peter
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top
UI for WinForms is Visual Studio 2017 Ready