Hi,
I’m using the following code in my CExtGridWnd-derived class to implement an "invert selection" feature:
long rows = RowCountGet();
long cols = ColumnCountGet();
if( !rows || !cols)
return;
// loop over all rows and add index to set if selected
set<long> selected;
for( long i=0; i<rows; i++) {
if( SelectionGetForCell( 0, i))
selected.insert( i);
}
// clear selections
OnContextDeselectAll();
// now get all selections minus the ones that were previously selected
for( long i=0; i<rows; i++) {
if( selected.find( i) == selected.end()) {
BOOL ret = SelectionSet( CRect( 0, i, cols-1, i), false);
ASSERT( ret);
}
}
Right now, it always selects the last row in the grid, rather than all of the ones set in the loop. If I’m reading the documentation correctly, bReplaceOldAreas should be false to preserve all existing selections, and bReplaceLastArea should be false so that the next selection is appended. I did a simple test by adding 5 lines to my grid, and then calling the following code:
SelectionSet( CRect(0,0,cols-1,1), false);
SelectionSet( CRect(0,3,cols-1,4), false);
This code also just selects the last region, and erases the previous one... I could have sworn this worked in a very early version of Prof-UIS.