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 3485408
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:54:14+00:00 2026-05-18T10:54:14+00:00

how to select items in listbox, if start dragging from one item to the

  • 0

how to select items in listbox, if start dragging from one item to the end of the dragging?

  • 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-05-18T10:54:15+00:00Added an answer on May 18, 2026 at 10:54 am

    I found this approach on a question on msdn but I can’t find it again so I can’t link it.. Anyway, this works pretty good, only problem being when dragging and scrolling at the same time, then it can miss a few items. I’ve created a custom control library called MultiSelectLibrary which you can use like this

    Add a reference to MultiSelectLibrary which can be downloaded from here (Source here)
    Add the namespace and the MultiSelectListBox with SelectionMode=”Extended” and it should work.

    xmlns:mslb="clr-namespace:MultiSelectLibrary.MultiSelectListBox;assembly=MultiSelectLibrary"
    
    <mslb:MultiSelectListBox SelectionMode="Extended" .../>
    

    If you rather just use some code behind you can do it like this (doing the same thing as the library)

    <ListBox SelectionMode="Extended"
             ...>
        <ListBox.ItemContainerStyle>
            <Style TargetType="{x:Type ListBoxItem}">
                <EventSetter Event="PreviewMouseUp" Handler="ListBoxItem_PreviewMouseUp"/>
                <EventSetter Event="PreviewMouseLeftButtonDown" Handler="ListBoxItem_PreviewMouseLeftButtonDown"/>
                <EventSetter Event="PreviewMouseMove" Handler="ListBoxItem_PreviewMouseMove"/>
            </Style>
        </ListBox.ItemContainerStyle>
    </ListBox>
    

    And in code behind

    private object _anchor, _lead;
    private Boolean _inMouseSelectionMode;
    private List<object> _selectedItems = new List<object>();
    
    private void ListBoxItem_PreviewMouseUp(object sender, MouseButtonEventArgs e)
    {
        _selectedItems.Clear();
        _inMouseSelectionMode = false;
        _anchor = null;
        _lead = null;
    }
    
    private void ListBoxItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
            return;
    
        _anchor = sender;
        _inMouseSelectionMode = true;
        _selectedItems.Clear();
        _selectedItems.Add(sender);
    }
    private void ListBoxItem_PreviewMouseMove(object sender, MouseEventArgs e)
    {
        if (!_inMouseSelectionMode)
            return;
    
        if (_lead != sender)
        {
            var last = _lead;
            _lead = sender;
    
            if (_selectedItems.Contains(_lead))
                _selectedItems.Remove(last);
            else
                _selectedItems.Add(_lead);
        }
    
        foreach (var item in _selectedItems)
            ((ListBoxItem)item).IsSelected = true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I remove items from, or add items to, a select box? I'm
I'm trying to figure out how to exclude items from a select statement from
I've almost got this working apart from one little annoying thing... Because the ListBox
I have one ListBox which has three Items in it. And also has one
For a ListView where I can select multiple items from the list, my method
I am building a table using the DataGridView where a user can select items
is there a quick way to sort the items of a select element? Or
I want to have a select-only ComboBox that provides a list of items for
In postgres you can do a comparison against multiple items like so: SELECT 'test'
How is it possible to programmatically select an item in a WPF TreeView ?

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.