.NET Framework Developer Center > .NET Development Forums > Windows Presentation Foundation (WPF) > How to lasso (drag & select) multiple items in gridview
Ask a questionAsk a question
 

AnswerHow to lasso (drag & select) multiple items in gridview

  • Wednesday, November 21, 2007 9:31 PMPerter Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    I am allowing multiselection in a gridview(listview) control and would like to let the user lasso their selection by clicking in one spot and dragging the mouse over the other items to select them.  Any idea if this is supported?  I haven't seen anything that might handle it.

Answers

All Replies

  • Wednesday, November 21, 2007 9:52 PMJeremiah Morrill Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I've implemented this before with making a user control that contained a canvas with a single rectangle in it.  The with a lil code-behind I hooked into the mousedown/up and mousemove events...positioning and sizing the rectangle as needed.  On the mouseup I simply detected which items are within the rectangle and set them to be selected.

     

    It's a bit of custom code, so if anyone has a better way of doing this...I'm interested also.

     

    Maybe the ink cavas could work in some facet...

     

    -Jer

  • Thursday, November 22, 2007 10:45 AMDenis Vuyka Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    As for lasso selections read the articles for InkCanvas. Another approach could be implementing the hit testing functionality. Read some articles towards HitTesting to get the basic understanding.

     

  • Monday, November 26, 2007 8:52 AMMarco Zhou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    I've given a quite similar solution in the following thread, you can easily tweak it a bit to make it work for ListView:

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2427163&SiteID=1

     

    Although this doesn't look like the lesso selection in the graphical editing program, but this might what you need.

     

    Hope this helps