Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9071507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:56:05+00:00 2026-06-16T17:56:05+00:00

I have a ListBox and I want to be able to click on multiple

  • 0

I have a ListBox and I want to be able to click on multiple items and then drag into another program. I can get it working fine for a single object. I just can’t get it working for more than 1.

I had a look at WPF Drag & drop from ListBox with SelectionMode Multiple but it completely stumped me (Tried to use it, but it didn’t work and I didn’t understand it.)

My current Drag ‘n’ Drop code is as follows.

<ListBox.ItemContainerStyle>
    <Style TargetType="{x:Type ListBoxItem}">
        <EventSetter Event="MouseDoubleClick" Handler="ListBoxItemDClick"/>
        <EventSetter Event="MouseDown" Handler="ReferenceList_PreviewMouseLeftButtonDown"/>
        <EventSetter Event="MouseMove" Handler="ReferenceList_PreviewMouseMove"/>
        <EventSetter Event="MouseUp" Handler="ReferenceListMouseUp"/>
        <Style.Triggers>
            ...
        </Style.Triggers>
    </Style>
</ListBox.ItemContainerStyle>

Private Sub ListBoxItemDClick(sender As Object, e As MouseButtonEventArgs) 'DoubleClick
    Dim PW As MainWindow = Window.GetWindow(MainPage)
    If PW IsNot Nothing Then
        Dim selite As ListBoxItem = DirectCast(ReferenceList.ItemContainerGenerator.ContainerFromItem(ReferenceList.SelectedItem), ListBoxItem) 
        PW.NewItem = False
        PW.EditItem = ReferenceList.SelectedItem
        PW.ChangeSlide(sender, 1)
    End If
End Sub

Private Sub ReferenceList_PreviewMouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs) 'Mouse Down on ListBoxItem
    Dim PW As MainWindow = Window.GetWindow(MainPage)
    StartPoint = e.GetPosition(Nothing)
    PW.Resizing = False
End Sub

Private Sub ReferenceListMouseUp(sender As Object, e As MouseButtonEventArgs) 'Mouse Up on ListBoxItem
    Dim PW As MainWindow = Window.GetWindow(MainPage)
    StartPoint = e.GetPosition(Nothing)
    PW.Resizing = True
End Sub

Private Sub ReferenceList_PreviewMouseMove(sender As Object, e As MouseEventArgs) 'MouseMove on ListBoxItem
    Dim PW As MainWindow = Window.GetWindow(MainPage)
    If PW.Resizing = False Then
        If ReferenceList.SelectedItems.Count = 1 Then
            Dim MousePosition As Point = e.GetPosition(Nothing)
            Dim Difference As Vector = StartPoint - MousePosition
            Dim StopDrop As Boolean = False
            Dim LBITEM As ListBoxItem = DirectCast(sender, ListBoxItem)
            If e.LeftButton = MouseButtonState.Pressed AndAlso (Math.Abs(Difference.X) > SystemParameters.MinimumHorizontalDragDistance Or Math.Abs(Difference.Y) > SystemParameters.MinimumVerticalDragDistance) Then
                PW.TempItem = LBITEM.DataContext
                Dim FN As String = PW.TempItem.PropLastName & ", " & PW.TempItem.PropFirstName.Substring(0, 1)
                Dim TT As String = PW.TempItem.PropTitle
                Dim YR As String = PW.TempItem.PropYear.ToString
                Dim ReferenceText As String = FN & " " & YR & ", " & TT
                Dim DragData As DataObject = New DataObject(DataFormats.StringFormat, ReferenceText)
                If DragData IsNot Nothing And StopDrop = False Then
                    DragDrop.DoDragDrop(sender, DragData, DragDropEffects.Copy)
                End If
            End If
        Else
            Dim TotalReference As String = "Reference Data"
            For Each ITEM As Object In ReferenceList.SelectedItems
                Dim MousePosition As Point = e.GetPosition(Nothing)
                Dim Difference As Vector = StartPoint - MousePosition
                Dim StopDrop As Boolean = False
                If e.LeftButton = MouseButtonState.Pressed AndAlso (Math.Abs(Difference.X) > SystemParameters.MinimumHorizontalDragDistance Or Math.Abs(Difference.Y) > SystemParameters.MinimumVerticalDragDistance) Then
                    PW.TempItem = ITEM
                    Dim FN As String = PW.TempItem.PropLastName & ", " & PW.TempItem.PropFirstName.Substring(0, 1)
                    Dim TT As String = PW.TempItem.PropTitle
                    Dim YR As String = PW.TempItem.PropYear.ToString
                    Dim ReferenceText As String = FN & " " & YR & ", " & TT
                    If TotalReference Is "Reference Data" Then
                        TotalReference = ReferenceText
                    Else
                        TotalReference = ReferenceText & vbCr & ReferenceText
                    End If
                End If
                Dim DragData As DataObject = New DataObject(DataFormats.StringFormat, TotalReference)
                If DragData IsNot Nothing And StopDrop = False Then
                    DragDrop.DoDragDrop(sender, DragData, DragDropEffects.Copy)
                End If
            Next
        End If
    End If
End Sub

Variables:

PW.Resizing (Boolean on MainWindow that determines whether window is resizing (True/False)
PW.TempItem (Declared on MainWindow as: Public TempItem as Reference 'Reference is my own class like a Student or such class to store data)
Private StartPoint As Point
ReferenceList is the ListBox containing all the ListBoxItems.

If I need to give more details please let me know. I can’t tell what is wrong with my code for multiple items being dragged.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:56:06+00:00Added an answer on June 16, 2026 at 5:56 pm

    Never mind, I found my error. I replaced this line:

    TotalReference = ReferenceText & vbCr & ReferenceText
    

    With this line:

    TotalReference = TotalReference & vbCr & ReferenceText
    

    And its all working now!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListBox and I want to be able to click on multiple
I have a listbox and I want to loop through each of the items
I have a listbox where I want to copy and paste items within that
well i have a listbox with some items inside. i want to detect a
I want a ListBox full of items. Although, each item should have a different
I have a listbox (listBox) and a dropdown list(dropDown). I want to be able
I have an HTML listbox, I want to be able to select any value
I have a listbox, and I want to read all of the items in
I have a multi-select list box. I want to be able to select a
Hi have an listbox and i want external buttons to scroll the listbox. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.