2
votes

I am working with a DataGridView in winforms that I am handling the CellPainting event for to paint all the cells myself.

My grid is virtual and has all of it's data stored in a custom data structure centered around a MemoryStream.

All of my painting has been going fine, until a user Shift + clicks to select a large range of cells at once (25,000+), which have to be added to a selected cells collection, have a bunch of flags set, and other performance-draining operations.

Is there any way to prevent the DataGridView from "selecting" a cell so I can handle this operation separately in a more efficient manner?

1
am i understand correctly or where do you want to prevent the cell selection at form load or any specific condition...Enigma State
I don't want the user to EVER be able to fire the SelectionChanged eventChandlerPelhams
I think there are properties on the data grid that set how and when rows and columns can be clicked. You should be able to turn off all selecting of any kind in the designer.Justin

1 Answers

2
votes

A bit confused on the issue here.

If you don't want them to be able to select multiple-cells at all, set

dataGridView.MultiSelect = false

You say they ctrl+click 25k cells - are you suggesting they select 25k cells one-at-a-time (that is how ctrl+click works)? If you mean they shift-click to select a range, then simply handle the SelectionChanged event, and do whatever you need to do with dataGridView.SelectedRows. SelectionChanged will only be called once, for the entire selection.