| | | | Browse by category |
Problem
How can I outline the current row with a border?
Cause
Action
The following methods provide an example for how to outline the cells of the current row. The current row will be outlined with a special background color and text color. When the end-user moves through the grid, the cells of the previous row will be reset to their default appearance and the new row will be highlighted. Please note that in OnInitialUpdate(), the default outlining of the current cell is already disable and that the m_nOutlineRow attribute has been initialized.
// In the class definition, two new attributes // have been declared: // BOOL m_bRedrawOnMovedCurrentCell; // ROWCOL m_nOutlineRow; // // The first of the three overrides is OnLeftCell. // OnLeftCell is called after the old current cell // has been deactivated. So, at the time this event // is called, there is no current cell in the grid. // When we redraw the current row, the row will be // redrawn with its default appearance (no // highlighting). // BOOL CDbfBrowserView::OnLeftCell(ROWCOL nRow, ROWCOL nCol, ROWCOL nNewRow, ROWCOL nNewCol) |
|||||
// Unused: nCol, nNewCol; m_bRedrawOnMovedCurrentCell = FALSE; if (nNewRow > 0 && nNewRow != m_nOutlineRow) |
|||||
ROWCOL nOldRow = m_nOutlineRow; m_nOutlineRow = nNewRow; RedrawRowCol(CGXRange().SetRows(nOldRow), GX_UPDATENOW, FALSE); // Next time, OnMoveCurrentCell is called, // No further redrawing of current |
|||||
}
return TRUE; |
|||||
}
// The next override is GetStyleRowCol (you BOOL CDbfBrowserView::GetStyleRowCol(ROWCOL nRow, ROWCOL nCol, CGXStyle& style, GXModifyType mt, int nType) |
|||||
CMyBrowserView::GetStyleRowCol(nRow, nCol, style, mt, nType);
// You may also initialize the following // Check if this is the current row |
|||||
// Outline the cells of the // current row. NOTE: This is // only an example. You may // customize the behavior to // your specific needs. Using // the grids default outlining // of the current cell will // probably look better than this // sample (has a nicer border). if (IsCurrentCell(nRow, nCol)) { |
|||||
// Draw border in highlight // around current cell style.SetBorders(gxBorderAll, |
|||||
CGXPen().SetWidth(1).SetColor(COLOR_HIGHLIGHT)); | |||||
// NOTE: If you want to do this, // you should disable the default // outlining of the current cell // by placing the following lines // in your OnInitialUpdate routine: // // CGXProperties* pProp = GetParam()->GetProperties(); // pProp->SetUserProperty(GX_IDS_OUTLINECURRENTCELL, // (CGXStyle) pProp->sInvertNoBorder); |
|||||
} else { |
|||||
// Draw all other cells in current // row with highlight color style |
|||||
.SetInterior(::GetSysColor(COLOR_HIGHLIGHT)) .SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT)) .SetBorders(gxBorderTop, CGXPen().SetStyle(PS_DOT)) .SetBorders(gxBorderBottom, CGXPen().SetStyle(PS_DOT) ); |
|||||
} | |||||
}
return TRUE; |
|||||
}
// The last override for outlining the void CDbfBrowserView::OnMovedCurrentCell(ROWCOL nRow, ROWCOL nCol) |
|||||
// Redraw delayed when moved to a // new row (see OnLeftCell) if (m_bRedrawOnMovedCurrentCell) { |
|||||
RedrawRowCol(CGXRange().SetRows(nRow), GX_INVALIDATE, FALSE); | |||||
}
// Store the new row |
|||||
m_nOutlineRow = nRow; | |||||
CMyBrowserView::OnMovedCurrentCell(nRow, nCol); | |||||
} |