I too was having problems with retrieving cell selection from wxGrid so I have looked at the source and here is a solution that allows GetSelectedCells to return the correct information. There are other issues about row and column selectio that I will also discuss.
See bugs 1443956 http://sourceforge.net/tracker/index.ph ... tid=109863
and 1217401 http://sourceforge.net/tracker/index.ph ... tid=109863
Row, Column, and Cell selection information is stored in a wxGridSelection object in wxGrid. Once a grid is instantiated one needs to call CreateGrid or SetTable depending on how one is populating the grid. In 2.6.2 the CreateGrid method created a wxGridSelection object but in SetTable wxGridSelection was missing. That problem is fixed in 2.6.3 so both CreateGrid and SetTable will have a wxGridSelection object. (Side question: How do I relate this fix to the exact Bug for which it was fixed?)
Cell selection is kept in a wxGridCellCoordsArray in the wxGridSelection object but it is never populated. So a call to wxGrid::GetSelectedCells always returns 0.
So to fix this we look at the wxGrid::ProcessGridCellMouseEvent method where it calls wxGridSelection::SelectBlock on Event.LeftUp (wxGridSelection is m_selection in the code). In SelectBlock we are missing any code to populate the cells. wxGridSelection is in gridsel.cpp. So about line 515 we need to add the following code (standards aside):
Code: Select all
for (int i = topRow; i <= bottomRow; i++)
for (int j = leftCol; j <= rightCol; j++)
Now GetSelectedCells returns the correct information.
1) GetSelectedRows and GetSelectedCols still return 0. They only report rows and columns if the row and column is selected in the row or column header. If the row or column is selected by just selecting cells they report 0. One could debate rather that is proper behavoir. If in cell selection mode rather than row selection mode is a row consider selected if at least one but less than all cells in that row are selected?
2) When only one cell is selected but the mouse is not dragged (or is that drug) the cell border is highlighted rather than background color highlighting. What is the mode of the cell at that point and should it be selected or not?
3) There seems to be a lot of unneccesary code in SelectBlock. I am not sure of the intent or where all SelectBlock is used but all the code about checking to see if a block is selected relative to the new selection and then deselecting it seems unnecessary from my 10,000 foot view. If I am selecting a new block why not just deselect everything first. Perhaps there is a case where I might be selecting an additional block.
4) There may be other cases such as would occur with CTRL, SHIFT, ALT, etc that may need to be examined.
So what is the process (or where is the process documented) of getting this code into the code base?