Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - CXTListBase::AddColumn -- ItemCount = 0?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTListBase::AddColumn -- ItemCount = 0?

 Post Reply Post Reply
Author
Message
scruzer View Drop Down
Groupie
Groupie
Avatar

Joined: 01 February 2008
Location: United States
Status: Offline
Points: 13
Post Options Post Options   Thanks (0) Thanks(0)   Quote scruzer Quote  Post ReplyReply Direct Link To This Post Topic: CXTListBase::AddColumn -- ItemCount = 0?
    Posted: 19 May 2008 at 2:42pm
From toolkit v11 -- In AddColumn, this code:
 
 int iIndex = pHeaderCtrl->GetItemCount();
 if (nWidth == -1 && iIndex >= 0 )
 {
  // Get the column width of the previous column from header control
  HD_ITEM hd_item;
  hd_item.mask = HDI_WIDTH;               //indicate that we want the width
  pHeaderCtrl->GetItem(iIndex - 1, &hd_item);
  nWidth = hd_item.cxy;
 }
doesn't get a valid hd_item when iIndex = 0!
 
 
 
 
Back to Top
Smucker View Drop Down
Senior Member
Senior Member
Avatar

Joined: 02 February 2008
Status: Offline
Points: 156
Post Options Post Options   Thanks (0) Thanks(0)   Quote Smucker Quote  Post ReplyReply Direct Link To This Post Posted: 19 May 2008 at 6:11pm
Perhaps because you asked it to get item iIndex - 1.

As good practice, you may also want to zero any structure you pass to APIs. (I don't think it matters for the header control):

  HD_ITEM hd_item = {0};


Product: Xtreme Toolkit Pro version 13.2 (Unicode, static build)

Platform: Windows 200x/XP/Vista/Win7 (32/64 bit)

Language: Visual C++ 9.0 (Studio 2008)

Back to Top
scruzer View Drop Down
Groupie
Groupie
Avatar

Joined: 01 February 2008
Location: United States
Status: Offline
Points: 13
Post Options Post Options   Thanks (0) Thanks(0)   Quote scruzer Quote  Post ReplyReply Direct Link To This Post Posted: 29 May 2008 at 2:21pm
Or, perhaps -- using the default parameter leads to the bug in the code?
 
virtual int AddColumn(
    LPCTSTR lpszColHeading,
    int nWidth = -1,
    int nFormat = LVCFMT_LEFT
);
 
again, looking at this code.  If you call this function the first time, with nWidth as the default parameter (-1)...  The call to GetItem will request item "-1". 
 
int CXTListBase::AddColumn(LPCTSTR lpszColHeading, int nWidth/*= -1*/, int nFormat/*= LVCFMT_LEFT*/)
{
  // if we are not in report mode return error.
   if ((GetWindowLong(m_pListCtrl->m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT)
      return -1;
   // get a pointer to the header control, if NULL return error.
   CHeaderCtrl* pHeaderCtrl = _xtGetHeaderCtrl();
   if (pHeaderCtrl == NULL)
      return -1;
   int iIndex = pHeaderCtrl->GetItemCount();   // could be 0!
   if (nWidth == -1 && iIndex >= 0 )
   {
      // Get the column width of the previous column from header control
      HD_ITEM hd_item;
      hd_item.mask = HDI_WIDTH; //indicate that we want the width
      pHeaderCtrl->GetItem(iIndex - 1, &hd_item);
      nWidth = hd_item.cxy;
   }
   return m_pListCtrl->InsertColumn(iIndex, lpszColHeading, nFormat, nWidth, iIndex);
}
 
 My fix, "don't use the default parameter". 
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.047 seconds.