Here is the current version of the CExtGridWnd::OnGridQueryDataProvider()
virtual method which instantiates and returns the memory-based data provider for grid cells. This data provider is used by default.
CExtGridDataProvider & CExtGridWnd::OnGridQueryDataProvider()
{
ASSERT_VALID( this );
if( m_pDataProvider != NULL )
{
ASSERT_VALID( m_pDataProvider );
return (*m_pDataProvider);
}
m_pDataProvider = new CExtMDP < CExtGridDataProviderMemory >;
ASSERT_VALID( m_pDataProvider );
return (*m_pDataProvider);
}
In the previous version of this method, a non decorated instance of the
CExtGridDataProviderMemory
class was used:
m_pDataProvider = new CExtGridDataProviderMemory;
The new
CExtMDP
template decorator class provides a memory data provider and a grid control with the ability to hide/show rows and or columns. This feature is essential for other new grid filtering feature. That is why the
SwapDroppedSeries
method of the data provider component now requires a non
NULL
pointer to the event receiver interface that is implemented in the
CExtGridWnd
class. We used your code in the updated version of the
CDemoGrid::OnCmdMsg()
method in the
SimpleGrids sample application. Here is the updated part of this method:
if( nID == ID_USE_PAINT_MANAGER_COLORS )
{
DWORD dwSiwGetStyleEx = SiwGetStyleEx();
BOOL bUsedPmColors =
( (dwSiwGetStyleEx&__EGWS_EX_PM_COLORS) != 0 )
? TRUE : FALSE;
if( nCode == CN_COMMAND )
{
// if( pHandlerInfo != NULL )
// return TRUE;
// SiwModifyStyleEx(
// bUsedPmColors ? 0 : __EGWS_EX_PM_COLORS,
// bUsedPmColors ? __EGWS_EX_PM_COLORS : 0,
// true
// );
bool bUp = CExtPopupMenuWnd::IsKeyPressed( VK_CONTROL ) ? true : false;
LONG lCurSel = SelectionGetFirstRowInColumn(0L);
if( lCurSel < 0 || ( bUp && lCurSel < 1) || ( !bUp && lCurSel >= RowCountGet() - 1) )
return TRUE;
CExtGridDataProvider & dp = OnGridQueryDataProvider();
ULONG nRowOffset = 0L; dp.CacheReservedCountsGet( NULL, &nRowOffset );
if ( dp.SwapDroppedSeries(false, lCurSel + nRowOffset, (bUp ? lCurSel-1 : lCurSel+2) + nRowOffset, this ) )
{
// lCurSel = (bUp ? lCurSel-1 : lCurSel+1);
// FocusSet(CPoint(0, lCurSel));
OnSwInvalidate( true );
}
return TRUE;
} // if( nCode == CN_COMMAND )
else if( nCode == CN_UPDATE_COMMAND_UI )
{
CCmdUI * pCmdUI = (CCmdUI *)pExtra;
ASSERT( pCmdUI != NULL );
pCmdUI->Enable( TRUE );
pCmdUI->SetRadio( bUsedPmColors );
} // else if( nCode == CN_UPDATE_COMMAND_UI )
return TRUE;
} // if( nID == ID_USE_PAINT_MANAGER_COLORS )
Now you can click the
Use Paint Manager Colors button in the toolbar with or without the
Ctrl key pressed and you will see the correctly swapped rows in the currently selected grid control. We used the
Order Details grid with the full row selection model in our tests. Any other grid can also be used if you set the focus/selection to the first column for allowing the
LONG lCurSel = SelectionGetFirstRowInColumn(0L);
to detect selection. Please note, when the
CExtGridWnd
control receives events from the data provider component via virtual methods of the
IDataProviderEvents
interface, then the grid automatically manages focus and selection ranges. So, you don’t need to re-assign grid focus/selection.
Alternatively, you can simply instantiate the
CExtGridDataProviderMemory
class "AS IS" instead of its
CExtMDP < CExtGridDataProviderMemory >
decorated version used by default.