1
votes

I have a resizeable CListCtrl and I want to avoid any item being displayed partially, ever.

For example:

partially visible item: item 9

I want Item 9 to not be displayed in this case. Is there a flag or method for this? How would you go about solving this issue?

I tried the following and it was no good:

void CMyCListCtrl::OnEndScrolling()
{
    int iCount = this->GetCountPerPage();
    EnsureVisible(iCount - 1, FALSE);
}

after catching

...

ON_NOTIFY( LVN_ENDSCROLL, IDC_LIST1, OnEndScroll )

...

   void CWheelTestDlg::OnEndScroll(NMHDR* pNMHDR, LRESULT* pResult)
   {
       LPNMLVSCROLL pnmLVScroll = (LPNMLVSCROLL) pNMHDR;

       m_MyListCtrl.OnEndScrolling();
       *pResult = 0;
   }

In the CListCtrl parent dialog. (which I don't want to do, I want to do everything in my CListCtrl derived class only, if possible).

All I accomplish is showing item 9 completely, but item 10 is partially visible below it. If I have 30 items I don't want to scroll the list to show item 30, I want to show up to item 8 with no partially visible item below it.

2

2 Answers

2
votes

CListCtrl doesn't appear to support Integral Height. Here's a solution that accomplishes what you desire by forcefully changing the control height [with commented conditions] (http://www.codeproject.com/Messages/418084/Socket-accept-call.aspx):

/////////////////////////////////////////////////////////////////////////////////
// This assumes a REPORT-style CListCtrl.
//
// Resize the control. This works correctly only if scrolling is disabled. If
// there is scrolling, then setting to the size from ApproximateViewRect() will
// always give scroll bars showing. Which is irritating.
//
// We need to adjust the vertical size from what ApproximateViewRect() returns
// by one row minus border width
//////////////////////////////////////////////////////////////////////////////////
CSize sz = m_list.ApproximateViewRect();    // always adds room for a new row

CRect itRect;   // Get the height of a single row (there had better *be* a row!)
m_list.GetItemRect(0, &itRect, LVIR_BOUNDS);

int vOffset = itRect.Height() - 3;  // leave a little 'cuz it looks better
m_list.SetWindowPos(NULL, 0, 0, sz.cx, sz.cy - vOffset,
    SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOMOVE);
1
votes

I have the similar problem in wince, and find a solution accidentally. No direct solution in internet, so i decide to re-position scroll bar after receive some message, and the only message i can used in wince is WM_LBUTTONDOWN, other messages such as OnEndScroll are not called, maybe something wrong in my code.

Whatever, i use Timer(ON_WM_TIMER) to re-position scroll bar when receive WM_LBUTTONDOWN message, then find that list control doesn't scroll automatically! then i remain a empty OnTimer function and remove everything else. It works, and i guess list control use Timer to scroll partial row.

Hope useful to you.