<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ListControl + sort]]></title><description><![CDATA[<p>ich versuche verzweifelt mein<br />
listcontrol dazu zu bekommen, dass es nach einer<br />
spalte sortiert. in der listcontrol mehrere werte.<br />
die vergleichsfunktion wird auch mehrmals aufgerufen,<br />
seltsamerweise sind die parameter lParam1 und lParam2 immer 0<br />
(bei jedem aufruf, dh. es wird nicht sortiert):</p>
<pre><code class="language-cpp">void KlasseX::OnLvnColumnclickmeinListControl(NMHDR *pNMHDR, LRESULT *pResult)
{
  meinListControl.SortItems( list_compare, (LPARAM)&amp;meinListControl );
}

// ...
// die callback funktion wird mehrere male aufgerufen immer mit
// lParam1 und lParam2 == 0
int CALLBACK
	list_compare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	// lParamSort contains a pointer to the list view control.
   CListCtrl* pListCtrl = (CListCtrl*) lParamSort;

   // LParam1 und lParam2 sind IMMER 0
   // strItem hat den korrekten inhalt von zeile 0 und SPALTE_1
   CString    strItem1 = pListCtrl-&gt;GetItemText( lParam1, SPALTE_1 );
   CString    strItem2 = pListCtrl-&gt;GetItemText( lParam2, SPALTE_1 );

   return strcmp(strItem2, strItem1);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/46064/listcontrol-sort</link><generator>RSS for Node</generator><lastBuildDate>Fri, 01 May 2026 09:45:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/46064.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 16 Aug 2003 00:03:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ListControl + sort on Sat, 16 Aug 2003 00:03:48 GMT]]></title><description><![CDATA[<p>ich versuche verzweifelt mein<br />
listcontrol dazu zu bekommen, dass es nach einer<br />
spalte sortiert. in der listcontrol mehrere werte.<br />
die vergleichsfunktion wird auch mehrmals aufgerufen,<br />
seltsamerweise sind die parameter lParam1 und lParam2 immer 0<br />
(bei jedem aufruf, dh. es wird nicht sortiert):</p>
<pre><code class="language-cpp">void KlasseX::OnLvnColumnclickmeinListControl(NMHDR *pNMHDR, LRESULT *pResult)
{
  meinListControl.SortItems( list_compare, (LPARAM)&amp;meinListControl );
}

// ...
// die callback funktion wird mehrere male aufgerufen immer mit
// lParam1 und lParam2 == 0
int CALLBACK
	list_compare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	// lParamSort contains a pointer to the list view control.
   CListCtrl* pListCtrl = (CListCtrl*) lParamSort;

   // LParam1 und lParam2 sind IMMER 0
   // strItem hat den korrekten inhalt von zeile 0 und SPALTE_1
   CString    strItem1 = pListCtrl-&gt;GetItemText( lParam1, SPALTE_1 );
   CString    strItem2 = pListCtrl-&gt;GetItemText( lParam2, SPALTE_1 );

   return strcmp(strItem2, strItem1);
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/333359</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/333359</guid><dc:creator><![CDATA[entelechie]]></dc:creator><pubDate>Sat, 16 Aug 2003 00:03:48 GMT</pubDate></item><item><title><![CDATA[Reply to ListControl + sort on Sat, 16 Aug 2003 04:24:04 GMT]]></title><description><![CDATA[<p>In lParam1 und lParam2 stehen <em>nicht</em> die Indices der zu vergleichenden Einträge.</p>
<p>Siehe FAQ:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic.php?t=39109" rel="nofollow">http://www.c-plusplus.net/forum/viewtopic.php?t=39109</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/333405</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/333405</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Sat, 16 Aug 2003 04:24:04 GMT</pubDate></item><item><title><![CDATA[Reply to ListControl + sort on Sat, 16 Aug 2003 10:34:15 GMT]]></title><description><![CDATA[<p>danke, jetzt hab ich es hinbekommen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
ich habe aber eine einfachere loesung genommen.<br />
fuer alle, die sich nicht stundenlang durch die mengen der<br />
quelltexte wuehlen wollen hier meine loesung:</p>
<p>- zuerst muesst ihr beim hinzufuegen eines items noch zusaetzlich<br />
den data-wert des items setzen<br />
(dieser wird der sortier-funktion als LPARAM p1 und p2 uebergeben)</p>
<pre><code class="language-cpp">long index = m_ctrlBannedPlayers.GetItemCount();
m_ctrlBannedPlayers.InsertItem( index , &quot;&quot; ); // item hinzufuegen
// als daten einfach nochmal den index uebergeben
m_ctrlBannedPlayers.SetItemData( index , index );

// ....

// das setzen der funktion zum sortieren und sortieren
// im ereignis: LVN_COLUMNCLICK
if ( listControl.SortItems( list_compare, (LPARAM)&amp;listControl) == 0 )
  MessageBox( &quot;Sortieren nicht moeglich&quot;, &quot;Liste&quot; );
</code></pre>
<p>die sortierfunktion:</p>
<pre><code class="language-cpp">int CALLBACK list_compare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	// lParamSort contains a pointer to the list view control.
	CListCtrl* pListCtrl = reinterpret_cast&lt;CListCtrl*&gt;( lParamSort );

	LVFINDINFO info;

        // den index der items bestimmen
	info.flags = LVFI_PARAM;
	info.lParam = lParam1;
	int i1 = pListCtrl-&gt;FindItem( &amp;info );
	info.lParam = lParam2;
	int i2 = pListCtrl-&gt;FindItem( &amp;info );

        // den inhalt der items holen
	CString    strItem1 = pListCtrl-&gt;GetItemText( i1, LIST_COLUMNS_BANNED_PLAYERS_NAME );
	CString    strItem2 = pListCtrl-&gt;GetItemText( i2, LIST_COLUMNS_BANNED_PLAYERS_NAME );

	return strItem1.CompareNoCase( strItem2 );
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/333494</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/333494</guid><dc:creator><![CDATA[entelechie]]></dc:creator><pubDate>Sat, 16 Aug 2003 10:34:15 GMT</pubDate></item><item><title><![CDATA[Reply to ListControl + sort on Sat, 16 Aug 2003 11:05:06 GMT]]></title><description><![CDATA[<p>Es reicht in den meisten Fällen nicht aus, den ItemData-Wert nur beim Hinzufügen zu setzen. Du musst bei dieser Lösung vor <em>jedem</em> Sort-Aufruf die Indices in die ItemData-Werte neu reinschreiben, weil sich beim Sortieren, Einfügen oder Löschen die Indices der Items ändern, die ItemData-Werte aber nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/333516</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/333516</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Sat, 16 Aug 2003 11:05:06 GMT</pubDate></item><item><title><![CDATA[Reply to ListControl + sort on Sat, 16 Aug 2003 12:04:40 GMT]]></title><description><![CDATA[<p>MFK schrieb:</p>
<blockquote>
<p>Es reicht in den meisten Fällen nicht aus, den ItemData-Wert nur beim Hinzufügen zu setzen. Du musst bei dieser Lösung vor <em>jedem</em> Sort-Aufruf die Indices in die ItemData-Werte neu reinschreiben, weil sich beim Sortieren, Einfügen oder Löschen die Indices der Items ändern, die ItemData-Werte aber nicht.</p>
</blockquote>
<p>nein. das macht die FindItem-methode. die sucht zu einem ItemData-wert<br />
den passenden index.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/333556</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/333556</guid><dc:creator><![CDATA[entelechie]]></dc:creator><pubDate>Sat, 16 Aug 2003 12:04:40 GMT</pubDate></item><item><title><![CDATA[Reply to ListControl + sort on Sat, 16 Aug 2003 12:27:49 GMT]]></title><description><![CDATA[<p>entelechie schrieb:</p>
<blockquote>
<p>nein. das macht die FindItem-methode. die sucht zu einem ItemData-wert den passenden index.</p>
</blockquote>
<p>Jo, hast Recht, hatte ich übersehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/333569</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/333569</guid><dc:creator><![CDATA[MFK]]></dc:creator><pubDate>Sat, 16 Aug 2003 12:27:49 GMT</pubDate></item><item><title><![CDATA[Reply to ListControl + sort on Mon, 05 Apr 2004 14:18:41 GMT]]></title><description><![CDATA[<p>und habe malk das beispiel von oben genommen beim kompilieren bekomme ich diese Meldung,... ich weiss aber nicht zu tun mit ihr <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":-("
      alt="😞"
    /></p>
<p>schaut mal:<br />
error C2664: 'SortItems' : cannot convert parameter 1 from 'int (long,long,long)' to 'int (__stdcall *)(long,long,long)'<br />
None of the functions with this name in scope match the target type</p>
]]></description><link>https://www.c-plusplus.net/forum/post/495536</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/495536</guid><dc:creator><![CDATA[T1c4L]]></dc:creator><pubDate>Mon, 05 Apr 2004 14:18:41 GMT</pubDate></item><item><title><![CDATA[Reply to ListControl + sort on Mon, 05 Apr 2004 20:24:13 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>hast du das CALLBACK vergessen? Und Deklaration nicht vergessen, wenn der Aufruf vor der Definition stattfindet:</p>
<p>Deklaration<br />
[cpp]<br />
int <strong>CALLBACK</strong><br />
list_compare(LPARAM, LPARAM, LPARAM);<br />
[/cpp]</p>
<p>Definition</p>
<pre><code class="language-cpp">int CALLBACK list_compare(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
    // lParamSort contains a pointer to the list view control.
    CListCtrl* pListCtrl = reinterpret_cast&lt;CListCtrl*&gt;( lParamSort );

    LVFINDINFO info;

        // den index der items bestimmen
    info.flags = LVFI_PARAM;
    info.lParam = lParam1;
    int i1 = pListCtrl-&gt;FindItem( &amp;info );
    info.lParam = lParam2;
    int i2 = pListCtrl-&gt;FindItem( &amp;info );

        // den inhalt der items holen
    CString    strItem1 = pListCtrl-&gt;GetItemText( i1, LIST_COLUMNS_BANNED_PLAYERS_NAME );
    CString    strItem2 = pListCtrl-&gt;GetItemText( i2, LIST_COLUMNS_BANNED_PLAYERS_NAME );

    return strItem1.CompareNoCase( strItem2 );
}
</code></pre>
<p>MfG</p>
]]></description><link>https://www.c-plusplus.net/forum/post/495846</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/495846</guid><dc:creator><![CDATA[Probe-Nutzer]]></dc:creator><pubDate>Mon, 05 Apr 2004 20:24:13 GMT</pubDate></item></channel></rss>