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 General Discussion » Getting / setting selected rows in CExtGridWnd? Collapse All
Subject Author Date
Dave M Jun 30, 2005 - 7:24 AM

Hi, how can I get the selected row indexes from a CExtGridWnd object, or change the selections programmatically? I looked in the documentation and didn’t see anything related to this in this class and its base classes.

Technical Support Jun 30, 2005 - 12:30 PM

The selection model in the grid control is based on the array of rectangles. Each rectangle describes indices of left/top and right/bottom cells of a single rectangular selection region.

If your grid uses the single selection model, then the selection region consists of one rectangle only. The full-row and full-column selection models are also based on rectangles.

The data grid also supports two types of multiple selection models: excluded and non-excluded. The cell is assumed to be non-selected if it is covered by an even number of rectangles in the excluded model. The cell is assumed to be selected if it is covered by at least one rectangle in the non-excluded model.


Multiple selection models supported in Prof-UIS data grid control


The excluded multiple selection model is turned on if the __EGBS_SUBTRACT_SEL_AREAS style is applied by invoking the SiwModifyStyle() method of the grid control. The SimpleGrids sample demonstrates both excluded and non-excluded models.

Please note that each rectangle can be non-normalized, i.e. it is possible that left > right and/or top > bottom.

You can enumerate all the selected cells in column nColNo by using:
LONG nRowNo = wndGrid.SelectionGetFirstRowInColumn( nColNo );
    while( nRowNo >= 0 )
    {
        . . .
        nRowNo = wndGrid.SelectionGetNextRowInColumn( nColNo, nRowNo );
    }

You can use the SelectionGetLastRowInColumn() and SelectionGetpPrevRowInColumn() methods for traversing the same rows in the reversed order from bottom to top.

You can also enumerate all the selected cells in row nRowNo by using:

LONG nColNo = wndGrid.SelectionGetFirstColumnInRow( nRowNo );
    while( nColNo >= 0 )
    {
        . . .
        nColNo = wndGrid.SelectionGetNextColumnInRow( nColNo, nRowNo );
    }

You can use the SelectionGetLastColumnInRow() and SelectionGetPrevColumnInRow() methods for traversing the same columns in the reversed order from right to left.


The SelectionGetForCell( nColNo, nRowNo ) method allows you to detect whether a cell is selected regardless the selection model. You can invoke the SelectionGetHitCount( nColNo, nRowNo ) method to get the number of rectangles covering the specified cell. The SelectionGetAreaCount() method returns the total number of rectangles. The SelectionGet(), SelectionInsertAt(), SelectionSetAt(), SelectionRemoveAt(), SelectionIsEmpty() and SelectionUnset() methods are handy when you need to perform any operation with the array of rectangles which describe the current selection region. The two SelectionSet() overloaded methods allows you to append a new rectangle and optionally to remove previous rectangles. The FocusSet() method sets both focus and selection at once.

You can override the OnGbwSelectionChanged() virtual method to track when selection changes. You can also override the OnGbwSelectionCanModify() virtual method and return false if the current selection region cannot be changed. You can do the same for the focus by overriding the OnGbwFocusChanged() and OnGbwFocusChanging() methods.

Dave M Jun 30, 2005 - 8:32 AM

Ok, I found it. It’s not in the documentation, but in the header file, there are some useful methods. For everyone else that may be interested, I’ve included a sample below:

For selecting all rows:

long rows = RowCountGet();
long cols = ColumnCountGet();
    if( !rows || !cols)
        return;
SelectionSet( CRect(0, 0, cols-1, rows-1));