1

I have a CBCGPGridCtrl with virtual rows enabled (EnableVirtualMode). No problem with data display. On some event (right click from another window) I want to move the current visible part of the grid to a specific row. I couldn't find any specific method to do that. I tried a couple of different options:

1. I saw that manually moving the scrollbar cause a change in the values of variable like: m_nFirstVisibleItem, m_nLastVisibleItem and m_nVertScrollOffset, so I thought to replicate that using setScrollPos.

m_grid.SetScrollRange(SB_VERT, 0, size());
//....
m_grid.SetScrollPos(SB_VERT, gotoPosition);

But nothing happened and those variables were not affected.

  1. The other idea I tried was to select the row I was interested in, with:
m_grid.SetCurSel(gotoPosition);

None of those worked.

What is the right way to achieve that?

Federico
  • 743
  • 9
  • 22

1 Answers1

0

After a day of different attempts, the only solution I was able to get to work is to have a child of CBCGPGridCtrl and intervene explicitly on the value of m_nVertScrollOffset.

So, it was something like this:

class CChildGrid : public CBCGPGridCtrl
{
public:
    void SetScrollPos(int gotoPosition)
    {
        m_nVertScrollOffset = gotoPosition * m_nRowHeight;
    }
};
....
void CFoo::SetGridPosition()
{
   m_grid.SetScrollPos(125);
   m_grid.AdjustLayout();
}

Federico
  • 743
  • 9
  • 22