<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="https://syndication.webwiz.net/rss_namespace/">
 <channel>
  <title>Codejock Developer Community : CXTListBase::AddColumn -- ItemCount = 0?</title>
  <link>http://forum.codejock.com/</link>
  <description><![CDATA[This is an XML content feed of; Codejock Developer Community : Toolkit Pro : CXTListBase::AddColumn -- ItemCount = 0?]]></description>
  <copyright>Copyright (c) 2006-2013 Web Wiz Forums - All Rights Reserved.</copyright>
  <pubDate>Thu, 11 Jun 2026 17:24:14 +0000</pubDate>
  <lastBuildDate>Thu, 29 May 2008 14:21:37 +0000</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 12.04</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>forum.codejock.com/RSS_post_feed.asp?TID=10689</WebWizForums:feedURL>
  <image>
   <title><![CDATA[Codejock Developer Community]]></title>
   <url>http://forum.codejock.com/forum_images/codejock-logo.gif</url>
   <link>http://forum.codejock.com/</link>
  </image>
  <item>
   <title><![CDATA[CXTListBase::AddColumn -- ItemCount = 0? : Or, perhaps -- using the default...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=10689&amp;PID=35985&amp;title=cxtlistbaseaddcolumn-itemcount-0#35985</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=3714">scruzer</a><br /><strong>Subject:</strong> 10689<br /><strong>Posted:</strong> 29 May 2008 at 2:21pm<br /><br />Or, perhaps -- using the default parameter leads to the bug in the code? <DIV><strong></strong>&nbsp;</DIV><DIV><strong>virtual</strong> <strong>int</strong> AddColumn(<BR>&nbsp;&nbsp;&nbsp; LPCTSTR lpszColHeading, <BR>&nbsp;&nbsp;&nbsp; <strong>int</strong> nWidth = -1, <BR>&nbsp;&nbsp;&nbsp; <strong>int</strong> nFormat = LVCFMT_LEFT<BR>);</DIV><DIV>&nbsp;</DIV><DIV>again, looking at this code.&nbsp; If you call this function the first time, with nWidth as the default parameter (-1)...&nbsp; The call to GetItem will request item "-1".&nbsp; </DIV><DIV>&nbsp;</DIV><DIV><DIV>int CXTListBase::AddColumn(LPCTSTR lpszColHeading, int nWidth/*= -1*/, int nFormat/*= LVCFMT_LEFT*/)<BR>{<BR>&nbsp; // if we are not in report mode return error.<BR>&nbsp;&nbsp; if ((GetWindowLong(m_pListCtrl-&gt;m_hWnd, GWL_STYLE) &amp; LVS_TYPEMASK) != LVS_REPORT)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1;</DIV><DIV>&nbsp;&nbsp; // get a pointer to the header control, if NULL return error.<BR>&nbsp;&nbsp; CHeaderCtrl* pHeaderCtrl = _xtGetHeaderCtrl();</DIV><DIV>&nbsp;&nbsp; if (pHeaderCtrl == NULL)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1;</DIV><DIV>&nbsp;&nbsp; int iIndex = pHeaderCtrl-&gt;GetItemCount();&nbsp;&nbsp; // could be 0!<BR>&nbsp;&nbsp; if (nWidth == -1 &amp;&amp; iIndex &gt;= 0 )<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Get the column width of the previous column from header control<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HD_ITEM hd_item;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hd_item.mask = HDI_WIDTH; //indicate that we want the width<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pHeaderCtrl-&gt;GetItem(iIndex - 1, &amp;hd_item);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nWidth = hd_item.cxy;<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; return m_pListCtrl-&gt;InsertColumn(iIndex, lpszColHeading, nFormat, nWidth, iIndex);<BR>}</DIV><DIV>&nbsp;</DIV></DIV><DIV>&nbsp;My fix, "don't use the default parameter".&nbsp; </DIV>]]>
   </description>
   <pubDate>Thu, 29 May 2008 14:21:37 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=10689&amp;PID=35985&amp;title=cxtlistbaseaddcolumn-itemcount-0#35985</guid>
  </item> 
  <item>
   <title><![CDATA[CXTListBase::AddColumn -- ItemCount = 0? : Perhaps because you asked it to...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=10689&amp;PID=35434&amp;title=cxtlistbaseaddcolumn-itemcount-0#35434</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=3717">Smucker</a><br /><strong>Subject:</strong> 10689<br /><strong>Posted:</strong> 19 May 2008 at 6:11pm<br /><br />Perhaps because you asked it to get item iIndex - 1.<br><br>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):<br><br>&nbsp; HD_ITEM hd_item = {0};<br><br><br>]]>
   </description>
   <pubDate>Mon, 19 May 2008 18:11:42 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=10689&amp;PID=35434&amp;title=cxtlistbaseaddcolumn-itemcount-0#35434</guid>
  </item> 
  <item>
   <title><![CDATA[CXTListBase::AddColumn -- ItemCount = 0? : From toolkit v11 -- In AddColumn,...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=10689&amp;PID=35426&amp;title=cxtlistbaseaddcolumn-itemcount-0#35426</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=3714">scruzer</a><br /><strong>Subject:</strong> 10689<br /><strong>Posted:</strong> 19 May 2008 at 2:42pm<br /><br /><DIV>From toolkit v11 -- In AddColumn, this code:</DIV><DIV>&nbsp;</DIV><DIV>&nbsp;int iIndex = pHeaderCtrl-&gt;GetItemCount();<BR>&nbsp;if (nWidth == -1 &amp;&amp; iIndex &gt;= 0 )<BR>&nbsp;{<BR>&nbsp;&nbsp;// Get the column width of the previous column from header control<BR>&nbsp;&nbsp;HD_ITEM hd_item;<BR>&nbsp;&nbsp;hd_item.mask = HDI_WIDTH;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //indicate that we want the width<BR>&nbsp;&nbsp;pHeaderCtrl-&gt;GetItem(iIndex - 1, &amp;hd_item);<BR>&nbsp;&nbsp;nWidth = hd_item.cxy;<BR>&nbsp;}<BR></DIV><DIV>doesn't get a valid hd_item when iIndex = 0!</DIV><DIV>&nbsp;</DIV><DIV>&nbsp;</DIV><DIV>&nbsp;</DIV><DIV>&nbsp;</DIV>]]>
   </description>
   <pubDate>Mon, 19 May 2008 14:42:10 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=10689&amp;PID=35426&amp;title=cxtlistbaseaddcolumn-itemcount-0#35426</guid>
  </item> 
 </channel>
</rss>