Print Page | Close Window

Highlight Selected Report Columns

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Property Grid
Forum Description: Topics Related to Codejock Property Grid
URL: http://forum.codejock.com/forum_posts.asp?TID=22330
Printed Date: 28 April 2024 at 10:47pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Highlight Selected Report Columns
Posted By: eam74
Subject: Highlight Selected Report Columns
Date Posted: 18 June 2014 at 11:30am
Hi all,

I am working on a report control for my application and have a couple features that I haven't been able to find a solution for yet:

1. When a user clicks on an item, highlight the corresponding column.  If you sort, the column will be highlighted, but in my control the sort must be disabled, so there is no highlight.

2. Allow the user to select multiple columns.  I know this is possible because the report sample allows this, but I can't figure out where this option is set, unless this also is a consequence of disabling sorting.

3. (would be nice, but not critical) Remove the selection box around the row and customize the background color.  I am able to turn off highlighting for the row with wndReport.SelectionEnable(FALSE) but the box still shows up.  I found http://forum.codejock.com/forum_posts.asp?TID=3861" rel="nofollow - an old forum topic which suggests the function to override is GetItemMetrics, which I did, but it's not getting called - where exactly should this be added?

TIA


-------------
Xtreme ToolkitPro (C++) v16.1.0, Windows 7



Replies:
Posted By: eam74
Date Posted: 18 June 2014 at 2:26pm
Updates!

1. Based on the MessageRecord class in ReportSample, I created a custom record class which overrides GetItemMetrics.  This works to alter the colors of the currently selected row, but no others.  It appears to be calling this function for all rows so I don't know why it only changes colors for the selected row.

Code:

void CCustomRecord::GetItemMetrics(XTP_REPORTRECORDITEM_DRAWARGS* pDrawArgs, XTP_REPORTRECORDITEM_METRICS* pItemMetrics) {
    if (pDrawArgs->pColumn->GetIndex() == 3) { // hard-coded temporarily
        pDrawArgs->pControl->GetPaintManager()->m_clrHighlight = RGB(140, 240, 255);
        pDrawArgs->pControl->GetPaintManager()->m_clrHighlightText = RGB(0,0,0);
    } else if (pDrawArgs->pRow->IsSelected()) {
        pDrawArgs->pControl->GetPaintManager()->m_clrHighlight = RGB(240, 140, 255);
        pDrawArgs->pControl->GetPaintManager()->m_clrHighlightText = RGB(0,0,0);
    }
}

3. reportCtrl.ShowRowFocus(FALSE);


-------------
Xtreme ToolkitPro (C++) v16.1.0, Windows 7


Posted By: eam74
Date Posted: 18 June 2014 at 3:11pm
Further update on item #1:

Able to paint a particular column using a custom CXTPReportPaintManager that overrides DrawColumnBackground, as such:

void CCustomReportPaintManager::DrawColumnBackground(CDC* pDC, CXTPReportColumn* pColumn, CRect rcColumn, BOOL& bColumnPressed, BOOL& bDraggingFromHeader, CXTPReportHeader* pHeader) {
    if (pColumn->GetIndex()==1){ // column
        CXTPReportRecords* rows = pColumn->GetControl()->GetRecords();
        int i;
        for (i=0; i < rows->GetCount(); i++) {
            CXTPReportRecord* r = pColumn->GetControl()->GetRecords()->GetAt(i);
            r->GetItem(pColumn)->SetBackgroundColor(RGB(140, 240, 255));
        }
        pColumn->SetAlignment(xtpColumnTextRight);
    } else {
        pColumn->SetAlignment(xtpColumnTextCenter);
    }
}


Still some work left in tracking which is the currently selected column, and haven't found anything for item #2, but hopefully this is of use to someone searching in the future :)


-------------
Xtreme ToolkitPro (C++) v16.1.0, Windows 7



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net