Objective Grid: Outlining the current row with a border

Article ID: 434
Last updated: 27 Apr, 2018
Article ID: 434
Last updated: 27 Apr, 2018
Revision: 3
Views: 3100
Posted: 23 Jan, 2001
by Meltreger B.
Updated: 27 Apr, 2018
by Meltreger B.

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,
// redraw the whole row
m_bRedrawOnMovedCurrentCell = TRUE;

// No further redrawing of current
// cell necessary
return FALSE;

}

return TRUE;

}

// The next override is GetStyleRowCol (you
// may also override OnLoadCellStyle, there
// would be no difference). The reason I have
// choosen to override GetStyleRowCol is that
// OnLoadCellStyle is only availabe for
// CGXBrowserGrid-derived classes and I wanted
// to make this sample for outlining the
// current row as general as possible

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
// attribute in your OnInitialUpdate method.
m_bRefreshOnSetCurrentCell = TRUE;

// Check if this is the current row
if (!IsPrinting() && nRow > 0 && nCol > 0 && nRow == m_nOutlineRow)
{

// 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
// current row is OnMovedCurrentCell.
// This method will redraw the new row
// when the user has moved the current
// cell to a new row. The new row will
// be redrawn highlighted.

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
if (nRow > 0)

m_nOutlineRow = nRow;
CMyBrowserView::OnMovedCurrentCell(nRow, nCol);
}

This article was:   Helpful | Not helpful
Report an issue
Article ID: 434
Last updated: 27 Apr, 2018
Revision: 3
Views: 3100
Posted: 23 Jan, 2001 by Meltreger B.
Updated: 27 Apr, 2018 by Meltreger B.

Others in this category