Results 1 to 1 of 1

Thread: Changing the grid selection color

  1. #1

    Changing the grid selection color

    I have a grid where I want to change the default black color of the selection. I found this article that explained how to do that: https://rwkbp.makekb.com//entry/697/.

    Code:
    // upon init
    m_bRefreshOnSetCurrentCell = TRUE;
    
    // then
    BOOL CGrid::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 (GetInvertStateRowCol(nRow, nCol, GetParam()->GetRangeList()))
       {
          style.SetInterior(m_colors->GetGridSelectedLine());
          style.SetTextColor(m_colors->GetGridTextColor());
    
          bRet = TRUE;
       }
       
       return bRet;
    }
    
    void CGrid::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);
       }
    }
    The problem is that after selection changes, the previously selected cells are not correctly invalidated and repainted. The attached images shows this problem:
    1. the grid has several rows, that may have a user selected color for the background (grid1.png)
    2. a selection is done, it has the correct color, a grey instead of black (grid2.png)
    3. selection is removed, the previously selected cells are not painted with the corect background color (grid3.png)

    What do I need to do to have the previously selected cells correctly repainted?

    Thank you.
    Attached Images Attached Images
    Last edited by MariusBancila; 03-16-2017 at 02:36 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •