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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:33:07+00:00 2026-05-23T18:33:07+00:00

I have a simple implementation of a ListView in WPF that allows me to

  • 0

I have a simple implementation of a ListView in WPF that allows me to select multiple items in the list by holding the mouse button and dragging over the items. However, while holding the mouse button down, when I move the mouse outside the ListView, something strange happens with the selection. Ideally, I would just want the selection to remain the same, but instead it quickly cycles through all the selected items, leaving only the last item selected.

Here’s the code, have any ideas?

public class MultiSelectListView : ListView
{
   private bool m_isSelectionActive;

   public bool IsSelectionActive
   {
      get { return m_isSelectionActive; }
   }

   protected override DependencyObject GetContainerForItemOverride()
   {
      return new MultiSelectListViewItem(this);
   }

   protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
   {
      m_isSelectionActive = true;
   }

   protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
   {
      m_isSelectionActive = false;
   }
}

public class MultiSelectListViewItem : ListViewItem
{
   private readonly MultiSelectListView m_parent;

   public MultiSelectListViewItem(MultiSelectListView parent)
   {
      m_parent = parent;
   }

   protected override void OnMouseEnter(System.Windows.Input.MouseEventArgs e)
   {
      if (m_parent.IsSelectionActive)
         IsSelected = true;
   }
}
  • 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-23T18:33:08+00:00Added an answer on May 23, 2026 at 6:33 pm

    The funkiness you are experiencing happens when the mouse “drag” goes above the top of the list or below the bottom of the list. I think the behavior you set up will only work well if the selection mode is Multiple. The modifications to the MultiSelectListView below set the default selection mode to Multiple and assumes the user wants to start another selection with a left mouse click. You will still experience funkiness if the SelectionMode is set to Extended or Single in the XAML.

    public class MultiSelectListView : ListView
    {
        private bool m_isSelectionActive;
        public bool IsSelectionActive
        {
            get
            {
                return m_isSelectionActive;
            }
        }
        protected override DependencyObject GetContainerForItemOverride()
        {
            return new MultiSelectListViewItem(this);
        }
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            if (SelectionMode != SelectionMode.Single)
            {
                SelectedItems.Clear();
            }
            m_isSelectionActive = true;
        }
        protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            m_isSelectionActive = false;
        }
        public MultiSelectListView() : base()
        {
            SelectionMode = SelectionMode.Multiple;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a simple implementation of INotifyDataErrorInfo in a WPF 4.5 project. This
I have a quick and simple implementation: a ListView inside an updatepanel. To make
I have a very simple queue implementation that wraps a fixed array. It contains
I have an app with simple MVVM implementation with ListView on my View. I
I have a simple html multiline tooltip implementation: this.tooltip = function(tag) { xOffset =
I have a fairly simple set of functionality for which I have multiple implementations,
I have simple regex \.*\ for me its says select everything between and ,
I have simple win service, that executes few tasks periodically. How should I pass
We have in place a simple implementation of GA and have had for some
I have simple table that has about 80 rows, which I populate dynamically using

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.