![]() |
CXTListBase::AddColumn -- ItemCount = 0? |
Post Reply ![]() |
Author | |
scruzer ![]() Groupie ![]() ![]() Joined: 01 February 2008 Location: United States Status: Offline Points: 13 |
![]() ![]() ![]() ![]() ![]() 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!
|
|
![]() |
|
Smucker ![]() Senior Member ![]() ![]() Joined: 02 February 2008 Status: Offline Points: 156 |
![]() ![]() ![]() ![]() ![]() |
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) |
|
![]() |
|
scruzer ![]() Groupie ![]() ![]() Joined: 01 February 2008 Location: United States Status: Offline Points: 13 |
![]() ![]() ![]() ![]() ![]() |
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".
|
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |