This is a migrated thread and some comments may be shown as answers.

ListControl Drag&Drop with Descritpions

4 Answers 83 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Matias
Top achievements
Rank 1
Matias asked on 30 Jan 2013, 02:12 PM
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.

4 Answers, 1 is accepted

Sort by
0
Accepted
Peter
Telerik team
answered on 01 Feb 2013, 12:22 PM
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.
0
Matias
Top achievements
Rank 1
answered on 01 Feb 2013, 02:05 PM
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!
0
Matias
Top achievements
Rank 1
answered on 01 Feb 2013, 02:11 PM
Solved the Item.text issue. The correct way to retrieve that information is Item.Data.text.
Thanks again for the time spent.
0
Peter
Telerik team
answered on 06 Feb 2013, 12:16 PM
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.
Tags
DropDownList
Asked by
Matias
Top achievements
Rank 1
Answers by
Peter
Telerik team
Matias
Top achievements
Rank 1
Share this question
or