简体   繁体   中英

c# wpf need to multiselect grid cells with mouse (NOT DataGrid control)

I have a standard Grid in my WPF form with "n" rows and "n" columns.

I wish to select and highlight the background of a selection of cells in one row by using the mouse left down and "dragging" the "highlight" across to the cells - each cell's background is highlighted for each one that the mouse-left-down moves over.

I currently have code working that will select one cell - using the mouse left down event that I have attached to the textblock assigned to the cell (row/column).

Does anyone have any idea how I can do the multiple select?

I have seen this working on the telerik grid but I am not in the position to use the Telerik controls.

(Googling brings up loads of Datagrid answers that do not answer the problem)

Will post code if I need to.

This is for the standard grid control not the datagrid control.

Many thanks.

You said that you have code to get your single cell selection working, so I assume that you have code that will determine whether there is a Grid at the MousePosition when the user clicks the mouse button.

All you need to do to enable the multi select functionality is to also monitor the PreviewMouseLeftButtonUp event as well. If you detect that the mouse down point was over Grid cell (0, 1) and the mouse up point was over Grid cell (3, 1), then you can determine that the user has clicked and dragged across cells 1 - 4 in row 1 of the Grid .

thanks for your post sheridan - it helped me through the thought process of what I needed:

capture the events for:

  1. mouse left button down

  2. mouse move

  3. mouse left button up

all sorted :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM