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

  • Home
  • SEARCH
  • 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 8625697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:51:11+00:00 2026-06-12T07:51:11+00:00

The problem: My application requires a user to be able to select multiple entries

  • 0

The problem:

My application requires a user to be able to select multiple entries in a datagrid via a column of checkboxes. The desired behavior is that when you click on a checkbox in the column, it behaves like a normal checkbox, but if you drag over it while the left mouse button is down, its selection state changes to the opposite of what is was before.

What I have tried so far:

I have tried subclassing CheckBox and handling OnMouseEnter, but the first checkbox that is clicked seems to capture the mouse so no other checkboxes fire the OnMouseEnter event.

I have tried implementing a drag-and-drop hack, where the user clicks to select a checkbox, and then drags that checkbox over the others so the others recieve a DragOver event and can switch states. This solution causes the cursor to display as a circle with a slash when not over another checkbox during the drag and drop, which is not acceptable for this application.

What I would like:

I would like a method to implement a checkbox that has the functionality I describe, ideally in a xaml style or subclass that I can reuse, as this functionality is needed in multiple places in my application.

Is there an elegant way to achieve this effect?

  • 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-12T07:51:12+00:00Added an answer on June 12, 2026 at 7:51 am

    I did this in my application, very handy when you have to select, say, 30 checkBoxes.
    To do this, i handled the preview mouse event myself : PreviewMouseLeftButtonDown, PreviewMouseMove, PreviewMouseLeftButtonUp.

    In PreviewMouseLeftButtonDown : i get the mouse position relative to the control.
    In PreviewMouseMove : i draw a rectangle from start to current position if i am far enough from firstPoint. then i iterate in CheckBoxes, see if they intersect with rectangle, and highlight them if so (so the user know whiwh chexboxes will swap)
    In PreviewMouseLeftButtonUp : i do the swap for intersecting CheckBoxes.

    if it can help you, here’s the code i use. it is not MVVM (:-)) but works fine, it might give you ideas. it is an automatic translation from vb.net code.

    To make it work, you need a Canvas on top of your CheckBoxes (=within the same grid cell for instance), with property IsHitTestVisible=”False” .
    Within this Canvas, put a Rectangle nammed “SelectionRectangle” with proper fill and stroke, but with 0.0 Opacity.

    // '' <summary>
    // '' When Left Mouse button is pressed, remember where the mouse move start
    // '' </summary>
    private void EditedItems_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) {
        StartPoint = Mouse.GetPosition(this);
    }
    
    // '' <summary>
    // '' When mouse move, update the highlight of the selected items.
    // '' </summary>
    private void EditedItems_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e) {
        if ((StartPoint == null)) {
            return;
        }
        PointWhereMouseIs = Mouse.GetPosition(this);
        Rect SelectedRect = new Rect(StartPoint, PointWhereMouseIs);
        if (((SelectedRect.Width < 20) 
                    && (SelectedRect.Height < 20))) {
            return;
        }
        //  show the rectangle again
        Canvas.SetLeft(SelectionRectangle, Math.Min(StartPoint.X, PointWhereMouseIs.X));
        Canvas.SetTop(SelectionRectangle, Math.Min(StartPoint.Y, PointWhereMouseIs.Y));
        SelectionRectangle.Width = Math.Abs((PointWhereMouseIs.X - StartPoint.X));
        SelectionRectangle.Height = Math.Abs((PointWhereMouseIs.Y - StartPoint.Y));
        foreach (CheckBox ThisChkBox in EditedItems.Children) {
            object rectBounds = VisualTreeHelper.GetDescendantBounds(ThisChkBox);
            Vector vector = VisualTreeHelper.GetOffset(ThisChkBox);
            rectBounds.Offset(vector);
            if (rectBounds.IntersectsWith(SelectedRect)) {
                ((TextBlock)(ThisChkBox.Content)).Background = Brushes.LightGreen;
            }
            else {
                ((TextBlock)(ThisChkBox.Content)).Background = Brushes.Transparent;
            }
        }
    }
    
    // '' <summary>
    // '' When Left Mouse button is released, change all CheckBoxes values. (Or do nothing if it is a small move -->
    // '' click will be handled in a standard way.)
    // '' </summary>
    private void EditedItems_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e) {
        PointWhereMouseIs = Mouse.GetPosition(this);
        Rect SelectedRect = new Rect(StartPoint, PointWhereMouseIs);
        StartPoint = null;
        SelectionRectangle.Opacity = 0;
        //  hide the rectangle again
        if (((SelectedRect.Width < 20) 
                    && (SelectedRect.Height < 20))) {
            return;
        }
        foreach (CheckBox ThisEditedItem in EditedItems.Children) {
            object rectBounds = VisualTreeHelper.GetDescendantBounds(ThisEditedItem);
            Vector vector = VisualTreeHelper.GetOffset(ThisEditedItem);
            rectBounds.Offset(vector);
            if (rectBounds.IntersectsWith(SelectedRect)) {
                ThisEditedItem.IsChecked = !ThisEditedItem.IsChecked;
            }
            ((TextBlock)(ThisEditedItem.Content)).Background = Brushes.Transparent;
        }
    }
    

    Edit : i used that code within a user control. This control takes a list of booleans and a list of strings (caption) as argument, and builds (with a WrapPanel) an array of CheckBoxes having the right caption. And so you can select/unselect with the rectangle, and there are also two buttons to check all/uncheck all. I tried also to keep good column/rows ratio to handle selection of 7 to 200 booleans with a good column/row balance.

    An exemple of use of the BooleanEdit User Control within a Window

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

Sidebar

Related Questions

I'm currently working a problem that requires my web application to generate a chart
I made a C# Windows Forms application that requires the user to login using
In our application the user is able to edit multiple rows at the same
The problem is: my application shows a WebView for a user, and after when
I have problem with my application. I have table report, there are 2 column
My application requires current location of the user. For this I have implemented the
I am currently developing a site using SSL that requires users to be able
my application requires the user to switch between several screens. The way I'm doing
I have an application that requires to use QWebView::setContent() to load some HTML content
I'm working on an application that requires the use of both JPA/Hibernate and RMI.

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.