Objective Grid: Displaying selected cells with a user-defined text and background color

Article ID: 697
Last updated: 11 Jun, 2018
Article ID: 697
Last updated: 11 Jun, 2018
Revision: 3
Views: 3189
Posted: 23 Jan, 2001
by Meltreger B.
Updated: 11 Jun, 2018
by Meltreger B.

Problem


How can I display selected cells with a user-defined text and background color or use the highlight text and background color from the system settings?


Cause



Action


By default Objective Grid is only inverting selected cells with CDC::InvertRect(), but by overriding the following two methods, you will be able to change the appearance of selected cells.

Please note that in earlier versions of this article we mentioned to set m_bCacheCurrentCell = FALSE. This was wrong. Instead you should set m_bRefreshOnSetCurrentCell = TRUE; This also solves the problem that this solution did not work with listbox mode.

Example:

In your OnInitialUpdate() routine, you should change the following attribute:

// Force that current cell is redrawn when user
// navigates through the grid
m_bRefreshOnSetCurrentCell = TRUE;

Next, you should override the following two methods:

BOOL CGridSampleView::GetStyleRowCol(ROWCOL nRow, ROWCOL nCol, CGXStyle& style, GXModifyType mt, int nType)
{
// Load stored style information of the cell
BOOL bRet = CGXGridCore::GetStyleRowCol(nRow, nCol, style, mt, nType);

// Check invert state for individual cell
if (nType == 0 && GetInvertStateRowCol(nRow, nCol, GetParam()->GetRangeList()))
{

style.SetInterior(::GetSysColor(COLOR_HIGHLIGHT));
style.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
bRet = TRUE;
}

return bRet;

}

void CGridSampleView::DrawInvertCell(CDC* /*pDC*/, ROWCOL nRow, ROWCOL nCol, CRect rectItem)
{

// If DrawInvertCell has been called
// from OnDrawTopLeftBottomRight
// m_nNestedDraw is greater 0. There
// is no invalidation of the rectangle
// necessary because the cell has
// already been drawn.
if (m_nNestedDraw == 0)
{
// m_nNestedDraw equal to 0 means
// that PrepareChangeSelection,
// PrepareClearSelection or
// UpdateSelectRange did call
// this method.
CGXRange range;

if (GetCoveredCellsRowCol(nRow, nCol, range))

rectItem = CalcRectFromRowCol(range.top, range.left, range.bottom, range.right);
InvalidateRect(&rectItem);
}
}

This article was:   Helpful | Not helpful
Report an issue
Article ID: 697
Last updated: 11 Jun, 2018
Revision: 3
Views: 3189
Posted: 23 Jan, 2001 by Meltreger B.
Updated: 11 Jun, 2018 by Meltreger B.

Others in this category