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 » Bug in Collapse All
Subject Author Date
David Skok Aug 7, 2006 - 7:04 AM

Greetings!

A while ago I asked about how to keep track of the location of sorted items in grids and you pointed me to OnDataProviderSwapSeries. I had been using my own method and decided to switch to using OnDataProviderSwapSeries but there seems to be a problem. The sort does not match what is displayed. Furthermore the values of nRowColNo1, nRowColNo2 passed to OnDataProviderSwapSeries can be outside of the range of ...CountGet(); I have verified the problem sorting rows and don’t know if the problem exists sorting columns.

Am I correct in assuming that ...CountGet() returns the amount of interior Row/Columns and does not count the outside? The documentation does not specify.

void _ZoneGrid::OnDataProviderSwapSeries(
        bool bColumns, // true = sorting/swapping columns, false - rows
        LONG nRowColNo1,
        LONG nRowColNo2,
        LONG nSwapCounter
        )
{
CExtGridWnd::OnDataProviderSwapSeries( bColumns, nRowColNo1, nRowColNo2, nSwapCounter );

int Save;
int *axis = ( bColumns ) ? ColumnXlate : RowXlate;
int Endpoint = ( bColumns ) ? ColumnCountGet() : RowCountGet();

if( nRowColNo1 >= Endpoint ||
nRowColNo2 >= Endpoint )
return;

Save = axis[nRowColNo2];
axis[nRowColNo2] = axis[nRowColNo1];
axis[nRowColNo1] = Save;
}

Technical Support Aug 7, 2006 - 9:31 AM

The row/column indices in the grid data provider differ from those in the grid window but it is not difficult to establish a conversion between them. Here is how it can be done with row indices. In the grid window, row numbers are zero-based and all rows in the data area, in the header at top and in the header at bottom are enumerated independently:

Header row 0 at top
Header row 1 at top
Header row 2 at top
 
Data row 0
Data row 1
Data row 2
Data row 3
Data row 4
Data row 5
 
Header row 0 at bottom
Header row 1 at bottom
Header row 2 at bottom
You can get any row count using the CExtGridWnd’s API:
LONG nOuterRowCountAtTheTop = wndGrid.OuterRowCountTopGet();
LONG nInnerDataRowCount = wndGrid.RowCountGet();
LONG nOuterRowCountAtTheBottom = wndGrid.OuterRowCountBottomGet();
In the data provider, data rows are stored in a two dimensional memory data structure, which has the following layout:
Real index  0 --> Header row 0 at top
Real index  1 --> Header row 1 at top
Real index  2 --> Header row 2 at top
Real index  3 --> Header row 0 at bottom
Real index  4 --> Header row 1 at bottom
Real index  5 --> Header row 2 at bottom
Real index  6 --> Data row 0
Real index  7 --> Data row 1
Real index  8 --> Data row 2
Real index  9 --> Data row 3
Real index  10 --> Data row 4
Real index  11 --> Data row 5
During row sorting only the grid’s data rows get swapped to reach the desired sort order. The data provider notifications use data provider’s internal row indices described above. So, if you want to convert row numbers passed in the nRowColNo1 and nRowColNo2 parameters of the OnDataProviderSwapSeries() virtual method, then you should subtract the summary number of header rows:
LONG nOuterRowCountAtTheTop = wndGrid.OuterRowCountTopGet();
LONG nOuterRowCountAtTheBottom = wndGrid.OuterRowCountBottomGet();
 
LONG nTotalCountOfHeaderRows = nOuterRowCountAtTheTop + nOuterRowCountAtTheBottom;
 
LONG nZeroBasedDataRowIndexInGrid1 = nRowColNo1 - nTotalCountOfHeaderRows;
LONG nZeroBasedDataRowIndexInGrid2 = nRowColNo2 - nTotalCountOfHeaderRows;
 
#if (defined _DEBUG)
        LONG nInnerDataRowCount = wndGrid.RowCountGet();
        ASSERT( 0 <= nZeroBasedDataRowIndexInGrid1 && nZeroBasedDataRowIndexInGrid1 < nInnerDataRowCount );
        ASSERT( 0 <= nZeroBasedDataRowIndexInGrid2 && nZeroBasedDataRowIndexInGrid2 < nInnerDataRowCount );
#endif (defined _DEBUG)
You should use the nZeroBasedDataRowIndexInGrid1 and nZeroBasedDataRowIndexInGrid2 variables in your row position tracking code instead of the nRowColNo1 and nRowColNo2 variables.

The same technique can be used for column indices.