mfc >> owner drawn CListCtrl creates blank rows on reszing

by Zm9nYXJhc2k » Fri, 28 Jan 2005 23:49:02 GMT

I created an owner draw CListCtrl object (inside of another resizable
control).

CListCtrl::Create ( LVS_REPORT |
LVS_SINGLESEL |
LVS_OWNERDRAWFIXED |
WS_CHILD |
WS_VISIBLE |
WS_BORDER,
rect, pParentWnd, nID ) );
this->SetExtendedStyle ( LVS_EX_GRIDLINES );

Ive overload the DrawItem and MeasureItem methods as well. Ive overloaded
the WM_SIZE handler to fit all the columns on the control too.

When all the rows are displayed, everything works fine. When I have more
rows than can be displayed, and the control's (vertical) scrollbar appears, I
can happily scroll and select and identify and navigate to any row/column
that is visible. That all works fine as expected, however, if I (say) select
the last row, then increase the size of the control (vertically) to see all
the rows, some blank rows appear at the top of the control. The GetItem()
methods all work fine, I can still select and find any item, its just got
some rogue empty rows at the top. They will disappear if I shrink the control
back down, and select the top row.


Any suggestions ?


mfc >> owner drawn CListCtrl creates blank rows on reszing

by crimson13 » Sat, 29 Jan 2005 00:02:18 GMT






The control is 'owner drawn'. Does the program get to the drawing
function of those 'blank rows'? Are those blank rows representations of
rows that should be there? Or is the first visible row (non blank) the
first row that should be drawn (which I am assuming since you call them
rogue)?

crimson13



mfc >> owner drawn CListCtrl creates blank rows on reszing

by Zm9nYXJhc2k » Fri, 04 Feb 2005 00:21:02 GMT







DrawItem is called with all the indices for the correct rows, starting on
the first row. It just writes them starting at the (say) 2nd row. The blank
rows are just that, empty rows that should not be there. Example : I add 3
rows of data to the control, and they fill the first 3 rows as expected.
After doing the scrolling as I noted in the problem above, these 3 rows are
now in row (say) 2, 3 and 4 with row 1 empty. ALL the indexing methods work
fine, they just dont see those empty rows, as if they just dont exist - but I
can see them.

BTW, if I put

this->EnsureVisible( 0, FALSE );

in the WM_SIZE handler, the blank rows do NOT appear. This does
unfortunately force the CListCtrl to scroll to the first item, which I dont
want it to do.


Similar Threads

1. Owner Draw CListCtrl mind-boggling mystery

2. Can't create OWNER-DRAW button using Create()

I have simple owner draw button derived from CButton with folowing functions
:

//-------------------------------------------------------------------------/
/

BOOL CCustomButton::CreateNormal( CWnd *pParent, UINT nID )
{
 Create( _T(""), WS_CHILD | WS_VISIBLE , CRect(0,0,10,10), pParent, nID );
 ModifyStyle( BS_TYPEMASK, BS_OWNERDRAW, SWP_FRAMECHANGED );
 m_ToolTip.Create( this );
 m_bCreated = TRUE;
 return TRUE;
}

//--------------------------------------------------------------------------
//

void CCustomButton::PreSubclassWindow()
{
 if ( !m_bCreated )
 {
  ModifyStyle( BS_TYPEMASK, BS_OWNERDRAW, SWP_FRAMECHANGED );
  m_ToolTip.Create( this );
 }
 CButton::PreSubclassWindow();
}

When I have some buttons defined in the dialog template I can subclass them
without problems, but when I create button
by hand using 'CreateNormal( this, 9999 )' I get following error:

error in wincore.cpp: 311

AfxCbtFilterHook()
    CWnd::Attach( HWND hWnd )
        ASSERT( hWnd == NULL ); <- this assertion fails

I can create normal buttons in the same way without problems. Please help !
Kamil



3. Owner-draw CListCtrl selection problem

4. owner drawn Clistctrl

can any one tell me how to insert item using draw item() function and a
local structure (which contains the data to be inserted)in Clistctrl ??
thanks in advance,
ramz

5. Owner draw in CListCtrl

6. Column owner draw in CListCtrl

Hi all,

In my CListCtrl (report style) I need a column to be
in bold... so essentially I need 1 column to be owner
drawn, while leaving the rest of the columns alone...
I don't want to do ownerdraw style because I have
to draw the entire row, which is no easy, especially
when I have a column with checkbox... Any advice how
to accomplish what I want to do? 

Thanks! Any idea is welcomed.

7. CListCtrl owner draw paint issue

8. Owner draw CListCtrl, EnsureVisible, PreTranslateMessage

There is Owner draw CListCtrl with overriden DrawItem. This class has 
subitems arbitrary controls (CEdit, CButton...). It should be fine to detect 
arrows keys in controls to jump with caret in CEdit boxes in one column by 
pressed arrow key. I tried to catch it in CEdit -> PreTranslateMessage() in 
block if(pMsg->wParam == VK_UP) 
then to call EnsureVisible() to parent CListCtrl to be caret always visible 
and CListCtrl scrolls if needed. Problem is when first time it scrolls up, 
some infinite loop begins and CPU 100% . It seems that something wrong with 
this... Can be EnsureVisible() sent from PreTranslateMessage() of subcontrol 
?   
Or any tip how to catch keystroke and safely to call EnsureVisible() of 
parent CListCtrl ? Or some better solution ? 

Thx,
Peter