Unfortunately I cannot provide the entire code for the application but I have included below the relevant code snippets relating to the grid definition and initialisation.
Hope this helps,
David.
// --- CHistoryGrid class definition
CHistoryGrid::CHistoryGrid()
: m_nBkType( 1 )
{
HoverEventsSet(true, true);
HoverHighlightSet(true,false,false,false,true,false);
SiwModifyStyleEx(
__EGWS_EX_PM_COLORS
//|__EGBS_EX_CELL_TOOLTIPS_OUTER
|__EGBS_EX_CELL_EXPANDING_INNER,
0,
false
);
}
// --- Relevant CHistoryGrid functions
void CHistoryGrid::SetCellHeader(long colNo, CString text, long width, long style) {
CExtGridCellHeader * pCell = STATIC_DOWNCAST(
CExtGridCellHeader,
GridCellGetOuterAtTop(
colNo,
0L,
RUNTIME_CLASS(CExtGridCellHeader)
)
);
pCell->ExtentSet(width);
pCell->TextSet(text);
pCell->ModifyStyle(style, 0);
}
void CHistoryGrid::SetCell(long colNo, long rowNo, CString text, long style, CString data) {
CHistoryCell* pCell =
STATIC_DOWNCAST(
CHistoryCell,
GridCellGet(colNo,rowNo,0,0,RUNTIME_CLASS(CHistoryCell))
);
if(pCell != NULL) {
if(!text.IsEmpty())
pCell->TextSet(text);
pCell->ModifyStyle( style );
if(!data.IsEmpty())
pCell->m_Data = data;
}
}
void CHistoryGrid::SetCell(long colNo, long rowNo, CString text, COLORREF textColour, COLORREF bgndColour, long style, CString data) {
CHistoryCell* pCell =
STATIC_DOWNCAST(
CHistoryCell,
GridCellGet(colNo,rowNo,0,0,RUNTIME_CLASS(CHistoryCell))
);
if(pCell != NULL) {
if(!text.IsEmpty())
pCell->TextSet(text);
if(textColour != NULL)
pCell->m_TextColour = textColour;
if(bgndColour != NULL)
pCell->m_BgndColour = bgndColour;
pCell->ModifyStyle( style );
if(!data.IsEmpty())
pCell->m_Data = data;
}
}
// --- Grid DDX control mapping in HistoryReportView.cpp:
DDX_Control(pDX, IDC_HISTORY_LIST, m_Grid);
// --- Grid definition in HistoryReportView.h:
CHistoryGrid m_Grid;
// --- Grid initialisation
void CHistoryReportView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
//
CMyApp* pApp = (CMyApp*)AfxGetApp();
CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
CString sTemp;
CString sTemp2;
CTime* cTime;
CTimeSpan* cTimeSpan;
CTimeSpan* cTimeSpan2;
CTimeSpan* cTimeSpan3;
CTimeSpan* cTimeSpan4;
SYSTEMTIME sysTime;
COleDateTime* vDateTime;
COleDateTime* vDateTime1;
COleDateTime* vDateTime2;
CString sTime;
CString sDateTime, sDateTime2;
CString sOldDate, sNewDate;
CTime* cDateTime;
CTime* cDateTime2;
CTimeSpan cJourneyTimeSpan;
CString sJourneyDuration;
CTimeSpan cStopTimeSpan;
CString sStopDuration;
CString sDate, sDate2;
CString sSpeed;
CString sHeading;
CString sLocation;
CString sDistance;
CString sDuration;
CString sDurationDays, sDurationHours, sDurationMins, sDurationSecs;
double dSpeed;
double dDistance;
CString columnName;
long iItem;
int iIndex = -1;
int iTemp;
float fSpeedDivider;
float fDistanceDivider;
//
if(pApp->m_MeasurementUnits == "Miles") {
fSpeedDivider = 2.23694f;
fDistanceDivider = (0.6214f / 1000);
}
if(pApp->m_MeasurementUnits == "Kilometres") {
fSpeedDivider = 3.6f;
fDistanceDivider = (1.0f / 1000);
}
//
m_HistoryReportType = pMainFrame->m_HistoryReportType;
m_ReportData = pMainFrame->m_ReportData;
m_RecordCount = 0;
m_UserEarliestDate = pMainFrame->m_UserEarliestDate;
m_UserEarliestTime = pMainFrame->m_UserEarliestTime;
m_UserLatestDate = pMainFrame->m_UserLatestDate;
m_UserLatestTime = pMainFrame->m_UserLatestTime;
m_UserID = pMainFrame->m_UserID;
m_UserName = pMainFrame->m_UserName;
m_UserESN = pMainFrame->m_UserESN;
m_UserIconFile = pMainFrame->m_UserIconFile;
// set grid styles
m_Grid.SiwModifyStyle(
__ESIS_STH_PIXEL
//|__ESIS_STV_ITEM
//|__EGBS_SFM_FULL_ROWS
//|__EGBS_NO_HIDE_SELECTION
|__EGBS_GRIDLINES
,__ESIW_ST_VIRTUAL, false
);
// initialise list columns
m_Grid.OuterRowCountTopSet( 1L, false );
columnName.LoadString(IDS_COLUMN_DATE);
m_Grid.ColumnAdd(1, false);
m_Grid.SetCellHeader(0, columnName, 120, __EGCS_TA_HORZ_CENTER);
//
m_Grid.ColumnAdd(5, false);
columnName.LoadString(IDS_COLUMN_LOCATION);
m_Grid.SetCellHeader(1, columnName, 130, 0);
columnName.LoadString(IDS_COLUMN_SPEED);
m_Grid.SetCellHeader(2, columnName, 60, __EGCS_TA_HORZ_CENTER);
columnName.LoadString(IDS_COLUMN_I1);
m_Grid.SetCellHeader(3, columnName, 30, __EGCS_TA_HORZ_CENTER);
columnName.LoadString(IDS_COLUMN_I2);
m_Grid.SetCellHeader(4, columnName, 30, __EGCS_TA_HORZ_CENTER);
columnName.LoadString(IDS_COLUMN_I3);
m_Grid.SetCellHeader(5, columnName, 30, __EGCS_TA_HORZ_CENTER);
//
m_Grid.RowRemoveAll();
m_SelectedItem = -1;
if(m_UserID != 0) {
if(m_UserEarliestDate != "" && m_UserLatestDate != "") {
sTemp.Format("SELECT * FROM [History] WHERE [UserID]=%ld AND (DateValue([FixDateTime]) BETWEEN #%s# AND #%s#) ORDER BY [FixDateTime]",
m_UserID,
m_UserEarliestDate,
m_UserLatestDate,
);
} else {
sTemp.Format("SELECT * FROM [History] WHERE [UserID] = %ld ORDER BY [FixDateTime]", m_UserID);
}
//
// --- Display History Report ---
// initialise recordset
pApp->m_rsODBC_History->m_strSort = "";
pApp->m_rsODBC_History->m_strFilter = "";
pApp->m_rsODBC_History->Open(AFX_DB_USE_DEFAULT_TYPE, sTemp);
// fill list ctrl from database
if(!pApp->m_rsODBC_History->IsEOF()) {
iItem = 0;
pApp->m_rsODBC_History->MoveFirst();
while(!pApp->m_rsODBC_History->IsEOF()) {
cTime = new CTime();
cTime = &(pApp->m_rsODBC_History->m_FIXDATETIME);
sDate = cTime->Format("%d/%m/%Y %H:%M:%S");
//
if(pApp->isHistoryInRange(cTime, m_ReportData)) {
m_Grid.RowInsert(iItem, 1, false);
//m_Grid.RowAdd(1, false);
//sTemp.Format("Rows: %ld", m_Grid.RowCountGet());
//AfxMessageBox(sTemp, MB_OK, 0);
dSpeed = (double)(pApp->m_rsODBC_History->m_SPEED);
dSpeed *= fSpeedDivider;
sSpeed.Format("%3.2f", dSpeed);
sTemp.Format("%ld",pApp->m_rsODBC_History->m_ID);
// set date
m_Grid.SetCell(0L, iItem, sDate, 0, sTemp);
sLocation = pApp->m_rsODBC_History->m_LOCATION;
// set speed
m_Grid.SetCell(1L, iItem, sLocation, 0, ""); // set location
m_Grid.SetCell(2L, iItem, sSpeed, 0, ""); // set speed
if(pApp->m_rsODBC_History->m_INPUTS & 0x2) // set input #1
m_Grid.SetCell(3L, iItem, "Off", RGB(255,255,255), RGB(255,0,0), 0, "");
else
m_Grid.SetCell(3L, iItem, "On", RGB(255,255,255), RGB(0,255,0), 0, "");
if(pApp->m_rsODBC_History->m_INPUTS & 0x4) // set input #2
m_Grid.SetCell(4L, iItem, "Off", RGB(255,255,255), RGB(255,0,0), 0, "");
else
m_Grid.SetCell(4L, iItem, "On", RGB(255,255,255), RGB(0,255,0), 0, "");
if(pApp->m_rsODBC_History->m_INPUTS & 0x8) // set input #3
m_Grid.SetCell(5L, iItem, "Off", RGB(255,255,255), RGB(255,0,0), 0, "");
else
m_Grid.SetCell(5L, iItem, "On", RGB(255,255,255), RGB(0,255,0), 0, "");
//
iItem++;
m_RecordCount++;
}
//
pApp->m_rsODBC_History->MoveNext();
}
}
// Close ODBC recordset
try {
pApp->m_rsODBC_History->Close();
}
catch (CDBException* e) {
//AfxMessageBox(e->m_strError, MB_OK, 0);
pApp->WriteError(e->m_strError);
e->Delete();
}
// ----------------
//
m_Grid.ShowWindow(SW_SHOW);
CWnd::RepositionBars( 0, 0xFFFF, IDC_HISTORY_LIST);
m_Grid.OnSwUpdateScrollBars();
m_Grid.OnSwDoRedraw();
}