<?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 : RemoveRecordEx doesn&#039;t fix the selection</title>
  <link>http://forum.codejock.com/</link>
  <description><![CDATA[This is an XML content feed of; Codejock Developer Community : Report Control : RemoveRecordEx doesn&#039;t fix the selection]]></description>
  <copyright>Copyright (c) 2006-2013 Web Wiz Forums - All Rights Reserved.</copyright>
  <pubDate>Sat, 18 Apr 2026 00:00:21 +0000</pubDate>
  <lastBuildDate>Fri, 13 Jul 2007 15:11:30 +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=7596</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[RemoveRecordEx doesn&#039;t fix the selection : OK, another signature bug with...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=7596&amp;PID=24463&amp;title=removerecordex-doesnt-fix-the-selection#24463</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=2321">JohnCrenshaw</a><br /><strong>Subject:</strong> 7596<br /><strong>Posted:</strong> 13 July 2007 at 3:11pm<br /><br /><DIV>OK, another signature bug with a fix. I fixed this one OUTSIDE of the Codejock library, but the fix should really be migrated to the library itself.</DIV><DIV>&nbsp;</DIV><DIV>The problem was that calling RemoveRecordEx was leaving the selection at exactly the same indexes as before, which following a removal usually meant the wrong row. In my case, this was reall wierd, since clicking on a row would occasionally remove other rows in the report, causing the selected row to be a row other than the one that was clicked on.</DIV><DIV>&nbsp;</DIV><DIV>The solution is fairly basic, and I have Outlined it below. In my case, I already had a derived class, so I just overloaded RemoveRecordEx, since it is virtual. The code below describes the fix.</DIV><DIV>&nbsp;</DIV><DIV>One issue here is that fixing this in the library will break it for anybody that fixed it themselves outside the library, but I think the fix still belongs in CXTPReportControl, and not in subclasses for every program that uses it.</DIV><DIV>&nbsp;</DIV><DIV>The fix:</DIV><DIV>&nbsp;</DIV><DIV><table width="99%"><tr><td><pre class="BBcode"></DIV><DIV><FONT size=2><P></FONT><FONT color=#008000 size=2>// this function operates on the assumption that all rows removed will be</P></FONT><FONT size=2><P></FONT><FONT color=#008000 size=2>// in a block, all together. If more than one row is removed, the positions</P></FONT><FONT size=2><P></FONT><FONT color=#008000 size=2>// of the rows will be a to a+n, where a in the index of the first row, and</P></FONT><FONT size=2><P></FONT><FONT color=#008000 size=2>// n is the number of rows removed. Provided this is true, we can adjust the</P></FONT><FONT size=2><P></FONT><FONT color=#008000 size=2>// selection as a block, even when multiple rows are removed by the same call</P></FONT><FONT size=2><P></FONT><FONT color=#008000 size=2>// to this function.</P></FONT><FONT size=2><P></FONT><FONT color=#008000 size=2>// remember the index of the main row we are removing</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> </FONT><FONT color=#010001 size=2>nIndexOfRemoval</FONT><FONT size=2> = </FONT><FONT color=#010001 size=2>pRecord</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>GetIndex</FONT><FONT size=2>();</P><P></FONT><FONT color=#008000 size=2>// remember how many rows we HAD</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> </FONT><FONT color=#010001 size=2>nOldRowCount</FONT><FONT size=2> = </FONT><FONT color=#010001 size=2>m_pRecords</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>GetCount</FONT><FONT size=2>();</P><P></FONT><FONT color=#008000 size=2>// do the removal, and remember the return</P></FONT><FONT size=2><P></FONT><FONT color=#010001 size=2>BOOL</FONT><FONT size=2> </FONT><FONT color=#010001 size=2>bRet</FONT><FONT size=2> = </FONT><FONT color=#010001 size=2>CXTPReportControl</FONT><FONT size=2>::</FONT><FONT color=#010001 size=2>RemoveRecordEx</FONT><FONT size=2>(</FONT><FONT color=#010001 size=2>pRecord</FONT><FONT size=2>, </FONT><FONT color=#010001 size=2>bAdjustLayout</FONT><FONT size=2>);</P><P></FONT><FONT color=#008000 size=2>// calculate how many rows were removed</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> </FONT><FONT color=#010001 size=2>nRemovedRowCount</FONT><FONT size=2> = </FONT><FONT color=#010001 size=2>nOldRowCount</FONT><FONT size=2> - </FONT><FONT color=#010001 size=2>m_pRecords</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>GetCount</FONT><FONT size=2>();</P><P></FONT><FONT color=#008000 size=2>// fix the selection positions</P></FONT><FONT size=2><P></FONT><FONT color=#010001 size=2>CXTPReportSelectedRows</FONT><FONT size=2>* </FONT><FONT color=#010001 size=2>pSel</FONT><FONT size=2> = </FONT><FONT color=#010001 size=2>GetSelectedRows</FONT><FONT size=2>();</P><P></FONT><FONT color=#0000ff size=2>for</FONT><FONT size=2> (</FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> </FONT><FONT color=#010001 size=2>a</FONT><FONT size=2> = 0; </FONT><FONT color=#010001 size=2>a</FONT><FONT size=2> &lt; </FONT><FONT color=#010001 size=2>pSel</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>m_arrSelectedBlocks</FONT><FONT size=2>.</FONT><FONT color=#010001 size=2>GetSize</FONT><FONT size=2>(); </FONT><FONT color=#010001 size=2>a</FONT><FONT size=2>++)</P><P>{</P><P></FONT><FONT color=#008000 size=2>&nbsp;&nbsp; // reduce the start and end values for the block if needed</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>&nbsp;&nbsp; if</FONT><FONT size=2> (</FONT><FONT color=#010001 size=2>pSel</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>m_arrSelectedBlocks</FONT><FONT size=2>&#091;</FONT><FONT color=#010001 size=2>a</FONT><FONT size=2>&#093;.</FONT><FONT color=#010001 size=2>nIndexBegin</FONT><FONT size=2> &gt;= </FONT><FONT color=#010001 size=2>nIndexOfRemoval</FONT><FONT size=2>)</P><P>&nbsp;&nbsp; {</P><P></FONT><FONT color=#008000 size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // shift it down</P></FONT><FONT size=2><P></FONT><FONT color=#010001 size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSel</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>m_arrSelectedBlocks</FONT><FONT size=2>.</FONT><FONT color=#010001 size=2>ElementAt</FONT><FONT size=2>(</FONT><FONT color=#010001 size=2>a</FONT><FONT size=2>).</FONT><FONT color=#010001 size=2>nIndexBegin</FONT><FONT size=2> -= </FONT><FONT color=#010001 size=2>nRemovedRowCount</FONT><FONT size=2>;</P><P></FONT><FONT color=#008000 size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // sometimes a reduction by the full count is wrong, fix this by</P></FONT><FONT size=2><P></FONT><FONT color=#008000 size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // capping the removal count on the bottom.</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if</FONT><FONT size=2> (</FONT><FONT color=#010001 size=2>pSel</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>m_arrSelectedBlocks</FONT><FONT size=2>&#091;</FONT><FONT color=#010001 size=2>a</FONT><FONT size=2>&#093;.</FONT><FONT color=#010001 size=2>nIndexBegin</FONT><FONT size=2> &lt; </FONT><FONT color=#010001 size=2>nIndexOfRemoval</FONT><FONT size=2>)</P><P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</P><P></FONT><FONT color=#010001 size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSel</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>m_arrSelectedBlocks</FONT><FONT size=2>.</FONT><FONT color=#010001 size=2>ElementAt</FONT><FONT size=2>(</FONT><FONT color=#010001 size=2>a</FONT><FONT size=2>).</FONT><FONT color=#010001 size=2>nIndexBegin</FONT><FONT size=2> = </FONT><FONT color=#010001 size=2>nIndexOfRemoval</FONT><FONT size=2>;</P><P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</P><P>&nbsp;&nbsp; }</P><P></FONT><FONT color=#0000ff size=2>&nbsp;&nbsp; if</FONT><FONT size=2> (</FONT><FONT color=#010001 size=2>pSel</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>m_arrSelectedBlocks</FONT><FONT size=2>&#091;</FONT><FONT color=#010001 size=2>a</FONT><FONT size=2>&#093;.</FONT><FONT color=#010001 size=2>nIndexEnd</FONT><FONT size=2> &gt; </FONT><FONT color=#010001 size=2>nIndexOfRemoval</FONT><FONT size=2>)</P><P>&nbsp;&nbsp; {</P><P></FONT><FONT color=#008000 size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // shift it down</P></FONT><FONT size=2><P></FONT><FONT color=#010001 size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSel</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>m_arrSelectedBlocks</FONT><FONT size=2>.</FONT><FONT color=#010001 size=2>ElementAt</FONT><FONT size=2>(</FONT><FONT color=#010001 size=2>a</FONT><FONT size=2>).</FONT><FONT color=#010001 size=2>nIndexEnd</FONT><FONT size=2> -= </FONT><FONT color=#010001 size=2>nRemovedRowCount</FONT><FONT size=2>;</P><P>&nbsp;&nbsp; }</P><P></FONT><FONT color=#0000ff size=2>&nbsp;&nbsp; if</FONT><FONT size=2> (</FONT><FONT color=#010001 size=2>pSel</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>m_arrSelectedBlocks</FONT><FONT size=2>&#091;</FONT><FONT color=#010001 size=2>a</FONT><FONT size=2>&#093;.</FONT><FONT color=#010001 size=2>nIndexEnd</FONT><FONT size=2> &lt;= </FONT><FONT color=#010001 size=2>pSel</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>m_arrSelectedBlocks</FONT><FONT size=2>&#091;</FONT><FONT color=#010001 size=2>a</FONT><FONT size=2>&#093;.</FONT><FONT color=#010001 size=2>nIndexBegin</FONT><FONT size=2>)</P><P>&nbsp;&nbsp; {</P><P></FONT><FONT color=#008000 size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // this block has been removed out of existence</P></FONT><FONT size=2><P></FONT><FONT color=#010001 size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pSel</FONT><FONT size=2>-&gt;</FONT><FONT color=#010001 size=2>m_arrSelectedBlocks</FONT><FONT size=2>.</FONT><FONT color=#010001 size=2>RemoveAt</FONT><FONT size=2>(</FONT><FONT color=#010001 size=2>a</FONT><FONT size=2>);</P><P></FONT><FONT color=#010001 size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a</FONT><FONT size=2>--;</P><P>&nbsp;&nbsp; }</P><P>}</P><P></FONT><FONT color=#008000 size=2>// also adjust the focused row index the same way</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>if</FONT><FONT size=2> (</FONT><FONT color=#010001 size=2>m_nFocusedRow</FONT><FONT size=2> &gt;= </FONT><FONT color=#010001 size=2>nIndexOfRemoval</FONT><FONT size=2>)</P><P>{</P><P></FONT><FONT color=#008000 size=2>&nbsp;&nbsp; // shift it down</P></FONT><FONT size=2><P></FONT><FONT color=#010001 size=2>&nbsp;&nbsp; m_nFocusedRow</FONT><FONT size=2> -= </FONT><FONT color=#010001 size=2>nRemovedRowCount</FONT><FONT size=2>;</P><P></FONT><FONT color=#008000 size=2>&nbsp;&nbsp; // cap it</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>&nbsp;&nbsp; if</FONT><FONT size=2> (</FONT><FONT color=#010001 size=2>m_nFocusedRow</FONT><FONT size=2> &lt; </FONT><FONT color=#010001 size=2>nIndexOfRemoval</FONT><FONT size=2>)</P><P>&nbsp;&nbsp; {</P><P></FONT><FONT color=#010001 size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_nFocusedRow</FONT><FONT size=2> = </FONT><FONT color=#010001 size=2>nIndexOfRemoval</FONT><FONT size=2>;</P><P>&nbsp;&nbsp; }</P><P>}</P><P></FONT><FONT color=#008000 size=2>// return</P></FONT><FONT size=2><P></FONT><FONT color=#0000ff size=2>return</FONT><FONT size=2> </FONT><FONT color=#010001 size=2>bRet</FONT><FONT size=2>;</P></FONT></pre></td></tr></table></DIV>]]>
   </description>
   <pubDate>Fri, 13 Jul 2007 15:11:30 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=7596&amp;PID=24463&amp;title=removerecordex-doesnt-fix-the-selection#24463</guid>
  </item> 
 </channel>
</rss>