Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Problem with SelectionSet in CExtGridWnd Collapse All
Subject Author Date
Krustys Donuts Oct 10, 2006 - 8:41 AM

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.

Technical Support Oct 11, 2006 - 12:38 PM

We have debugged the CExtGridBaseWnd::SelectionSet() method invocation with the bReplaceOldAreas parameter set to false and the rest parameters having default values. The grid window was configured to subtract selection areas. In this case the CExtGridBaseWnd::SelectionSet() method works like the CExtGridBaseWnd::SelectionInsertAt() method. We can take a look at your project to find out what’s wrong.

Suhai Gyorgy Oct 10, 2006 - 9:29 AM

If your grid has the __EGBS_SUBTRACT_SEL_AREAS style, a simple SelectionInsertAt(-1, CRect(0,0,ColumnCountGet(), RowCountGet())); call solves your whole "invert selection" problem. But if you, for any reason, don’t want that style set, you might want to try calling the SelectionInsertAt method instead of SelectionSet method.

Krustys Donuts Oct 10, 2006 - 11:36 AM

Thanks, the style bit worked! However, I’d still like tech. support to comment on my previous code. It seems like there’s a bug in the framework, but I could be wrong.

Krustys Donuts Oct 10, 2006 - 9:50 AM

Interesting idea! I’ll take a look at that, thanks.