Note that there are some explanatory texts on larger screens.

plurals
  1. POFast way to select all cells in virtual DataGridView (WinForms)
    primarykey
    data
    text
    <p>I'm currently struggling with the performance of the WinForms DataGridView in virtual mode. There are scenarios where I have matrices of size 2000x2000 or even bigger ones within the DataGridView. I've managed to increase the overall performance regarding custom painting, scrolling etc. to my needs. The only point left is the selection of all cells. For a matrix of the size I mentioned, it takes about 10 seconds which is absolutely unacceptable.</p> <p>Facts: AutoSizeMode of rows and columns is set to none. RowHeadersWidthSize is set to visible rows only and columnsHeaderHeight size is set to disabled. I'm attached to the CellPainting event and the CellFormatting event. To makes sure that the operations I perform in there are not the culprit of the performance issue I temporarily detached from those events with no success at all.</p> <p>It is mandatory, that the selection mode of the cells is set to CellSelect. I know, that this is not the best for virtual data grids but thats what we need. I already tried to attach to CTRL + A and the mouse down on the cell (-1, -1) and to set the selection mode in there to fullRowSelect before rerouting the event to the base class. But this does not lead to a performance gain as well.</p> <p>I understand, that if one cell has for example a different painting than the adjacent ones, the complete row get unshared. This leads to all rows becoming unshared when selecting all cells, which I think is the culprit of the performance issue.</p> <p>Does anyone of you maybe have an alternative way to select all cells without unsharing all rows or with better performance?</p> <p><strong>[Edit]</strong> I've seen a comparable issue described <a href="https://stackoverflow.com/questions/9039989/how-to-selectall-in-a-winforms-virtual-listview">here</a> which is related to the ListView. Now I wonder if a similar solution would be available for the DataGridView as well?</p> <p><strong>[Edit 2]</strong> I just realized, that memory usage is also dramatically increasing when selecting all cells (Again I think the reason for this is unsharing all rows). For example I have a big data set that consists of 1 column and 2 million rows. When the DataGrid is established with all its values, the application uses around <strong>300 MB</strong> of memory. When now selecting all cells, the memory usage increases up to <strong>1.3 GB</strong> of memory.</p> <p><strong>[Current Workaround]</strong> As I wasn't yet able to find a proper solution for the given problem, I implemented a workaround to support complete selection for big matrices. Currently I override the behaviour of Ctrl + A and the click on the top left cell (-1, -1). In there I do not perform a selection on the grid itself, but only set the cells background color to the one that is used for selection. The user now sees all cells highlighted as if they where selected. As I use the DataGridView in virtual mode and the selection is synchronized between the grid and the underlying data structure, i set a special flag in the underlying data that everything shall be selected. When the user now clicks on any other cell, the selection behaviour is reset to default and the cells backcolor is as well reset.</p> <p>When in full selection mode, I also handle the 'GetClipboardContent' method to make sure that all cell values are copied to the clipboard (Currently this results in another performance issue but that is another story).</p> <p>Even though this is a working solution for the moment, I would of course still be interested in other ideas providing a solution based on the functionality provided by the DataGridView itself.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload