<?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[ListView Sortieren]]></title><description><![CDATA[<p>Hallo, ich habe ein kleines Problem.<br />
Ich nutze folgeneden Code um eine ListView zu sortieren, das problem dabei: Es wird immer nur die erste Spalte sortiert, egal wo ich hin klicke...<br />
Ich bin mir sicher jemand von euch kann mir sofort sagen woran es liegt.</p>
<pre><code class="language-cpp">#define NO_OF_SUBITEM 6
#define UP 1
#define DOWN 2

typedef struct _tagSORTDATA{
    HWND hwndList;
    int isortSubItem;
    int iUPDOWN;
} SORTDATA;

SORTDATA SortData;
static int sortsubno[NO_OF_SUBITEM] = {DOWN};
static int isortsubno; 

case WM_NOTIFY:
			 switch (((LPNMHDR) lParam)-&gt;code) {
				case LVN_COLUMNCLICK:
					char test[100] = &quot;&quot;;
					NMLISTVIEW *lpnmlistview;
					lpnmlistview = (LPNMLISTVIEW)lParam;
					isortsubno = lpnmlistview-&gt;iSubItem;

					if (sortsubno[isortsubno] == UP){
						sortsubno[isortsubno] = DOWN;
						MessageBox(NULL, &quot;DOWN&quot; , &quot;Server Error&quot;, MB_OK);
					} else{
						MessageBox(NULL, &quot;UP&quot; , &quot;Server Error&quot;, MB_OK);
						sortsubno[isortsubno] = UP;
					}
					SortData.hwndList = hwndList;
					SortData.isortSubItem = isortsubno;
					SortData.iUPDOWN = sortsubno[isortsubno];
					if(ListView_SortItemsEx(hwndList, MyCompProc, &amp;SortData) != TRUE)
						MessageBox(hwndMain, &quot;?????&quot;, &quot;Error&quot;, MB_OK);

				break;
			  }
			break;

int CALLBACK MyCompProc(LPARAM lp1, LPARAM lp2, LPARAM lp3)
{
    static LVFINDINFO lvf;
    static int nItem1, nItem2;
    static char buf1[MAX_PATH], buf2[MAX_PATH];
    SORTDATA *lpsd;

    lpsd = (SORTDATA *)lp3;

    lvf.flags = LVFI_PARAM;
    lvf.lParam = lp1;
    nItem1 = ListView_FindItem(lpsd-&gt;hwndList, -1, &amp;lvf);

    lvf.lParam = lp2;
    nItem2 = ListView_FindItem(lpsd-&gt;hwndList, -1, &amp;lvf);

    ListView_GetItemText(lpsd-&gt;hwndList, nItem1, lpsd-&gt;isortSubItem, buf1, sizeof(buf1));

    ListView_GetItemText(lpsd-&gt;hwndList, nItem2, lpsd-&gt;isortSubItem, buf2, sizeof(buf2));

    if(lpsd-&gt;iUPDOWN == UP)
        return(stricmp(buf1, buf2));
    else
        return(stricmp(buf1, buf2) * -1);
}
</code></pre>
<p>Danke und Gruss</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/183741/listview-sortieren</link><generator>RSS for Node</generator><lastBuildDate>Tue, 07 Jul 2026 01:12:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/183741.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 08 Jun 2007 11:49:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ListView Sortieren on Fri, 08 Jun 2007 11:49:08 GMT]]></title><description><![CDATA[<p>Hallo, ich habe ein kleines Problem.<br />
Ich nutze folgeneden Code um eine ListView zu sortieren, das problem dabei: Es wird immer nur die erste Spalte sortiert, egal wo ich hin klicke...<br />
Ich bin mir sicher jemand von euch kann mir sofort sagen woran es liegt.</p>
<pre><code class="language-cpp">#define NO_OF_SUBITEM 6
#define UP 1
#define DOWN 2

typedef struct _tagSORTDATA{
    HWND hwndList;
    int isortSubItem;
    int iUPDOWN;
} SORTDATA;

SORTDATA SortData;
static int sortsubno[NO_OF_SUBITEM] = {DOWN};
static int isortsubno; 

case WM_NOTIFY:
			 switch (((LPNMHDR) lParam)-&gt;code) {
				case LVN_COLUMNCLICK:
					char test[100] = &quot;&quot;;
					NMLISTVIEW *lpnmlistview;
					lpnmlistview = (LPNMLISTVIEW)lParam;
					isortsubno = lpnmlistview-&gt;iSubItem;

					if (sortsubno[isortsubno] == UP){
						sortsubno[isortsubno] = DOWN;
						MessageBox(NULL, &quot;DOWN&quot; , &quot;Server Error&quot;, MB_OK);
					} else{
						MessageBox(NULL, &quot;UP&quot; , &quot;Server Error&quot;, MB_OK);
						sortsubno[isortsubno] = UP;
					}
					SortData.hwndList = hwndList;
					SortData.isortSubItem = isortsubno;
					SortData.iUPDOWN = sortsubno[isortsubno];
					if(ListView_SortItemsEx(hwndList, MyCompProc, &amp;SortData) != TRUE)
						MessageBox(hwndMain, &quot;?????&quot;, &quot;Error&quot;, MB_OK);

				break;
			  }
			break;

int CALLBACK MyCompProc(LPARAM lp1, LPARAM lp2, LPARAM lp3)
{
    static LVFINDINFO lvf;
    static int nItem1, nItem2;
    static char buf1[MAX_PATH], buf2[MAX_PATH];
    SORTDATA *lpsd;

    lpsd = (SORTDATA *)lp3;

    lvf.flags = LVFI_PARAM;
    lvf.lParam = lp1;
    nItem1 = ListView_FindItem(lpsd-&gt;hwndList, -1, &amp;lvf);

    lvf.lParam = lp2;
    nItem2 = ListView_FindItem(lpsd-&gt;hwndList, -1, &amp;lvf);

    ListView_GetItemText(lpsd-&gt;hwndList, nItem1, lpsd-&gt;isortSubItem, buf1, sizeof(buf1));

    ListView_GetItemText(lpsd-&gt;hwndList, nItem2, lpsd-&gt;isortSubItem, buf2, sizeof(buf2));

    if(lpsd-&gt;iUPDOWN == UP)
        return(stricmp(buf1, buf2));
    else
        return(stricmp(buf1, buf2) * -1);
}
</code></pre>
<p>Danke und Gruss</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1301268</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1301268</guid><dc:creator><![CDATA[dadevelopa]]></dc:creator><pubDate>Fri, 08 Jun 2007 11:49:08 GMT</pubDate></item><item><title><![CDATA[Reply to ListView Sortieren on Fri, 08 Jun 2007 11:55:09 GMT]]></title><description><![CDATA[<p>Genau das selbe habe ich vor einer Stunde gemacht <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="🙂"
    /></p>
<pre><code>case LVN_COLUMNCLICK:
	{
		LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
		Sort.Colum = pnmv-&gt;iSubItem; [b]// Die Spalte wo geklickt wurde![/b]
		SendMessage(lpnmh-&gt;hwndFrom, LVM_SORTITEMS, (WPARAM) &amp;Sort, reinterpret_cast&lt;LPARAM&gt;(CompareFunc));
		Sort.Asc = !Sort.Asc;
		return TRUE;
	}
</code></pre>
<p>Such dir die Spalte raus und reagier darauf!</p>
<p>schirrmie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1301274</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1301274</guid><dc:creator><![CDATA[schirrmie]]></dc:creator><pubDate>Fri, 08 Jun 2007 11:55:09 GMT</pubDate></item><item><title><![CDATA[Reply to ListView Sortieren on Fri, 08 Jun 2007 12:05:24 GMT]]></title><description><![CDATA[<p>Was meinst du mit &quot;darauf reagieren&quot;? Soll ich für jede Spalte eine individuelle Sortierfunktion schreiben?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1301288</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1301288</guid><dc:creator><![CDATA[dadevelopa]]></dc:creator><pubDate>Fri, 08 Jun 2007 12:05:24 GMT</pubDate></item><item><title><![CDATA[Reply to ListView Sortieren on Fri, 08 Jun 2007 12:43:31 GMT]]></title><description><![CDATA[<p>Kannst du natürlich auch oder du machst das wie ich <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
Du übergibst die Spalte mit deiner &quot;Sortierstruktur&quot; die du ja auch hast. in meinem Fall</p>
<pre><code>Sort.Colum = pnmv-&gt;iSubItem; // Die Spalte wo geklickt wurde!
</code></pre>
<p>und meine Sortierfunktion sieht dann so aus</p>
<pre><code>int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
	...
	SortStruct *sort = (SortStruct*) lParamSort;
	...

	switch( sort-&gt;Colum ) {
	case 0: // erste Spalte
		...
		break;
	case 1: // zweite Spalte
		...
		break;
	case 2: // dritte Spalte
		...
		break;
	default:
		return 0;
	}
	return 0;
}
</code></pre>
<p>schirrmie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1301314</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1301314</guid><dc:creator><![CDATA[schirrmie]]></dc:creator><pubDate>Fri, 08 Jun 2007 12:43:31 GMT</pubDate></item><item><title><![CDATA[Reply to ListView Sortieren on Fri, 08 Jun 2007 13:56:29 GMT]]></title><description><![CDATA[<p>Wunderschön, ich habe mal deinen Ansatz verfolgt bis ich gemerkt habe, dass ich gar keine Differenzierung brauche. Hier mein Code:</p>
<p>Aufruf:</p>
<pre><code class="language-cpp">ListView_SortItemsEx(hwndList, MyCompProc, sortNo); //Letzer Parameter: Spalte wo geklickt wurde
</code></pre>
<p>Callback:</p>
<pre><code class="language-cpp">int CALLBACK MyCompProc(LPARAM lp1, LPARAM lp2, LPARAM lParamSort)
{
    char buf1[30], buf2[30];

	ListView_GetItemText(hwndList, lp1, lParamSort, buf1, sizeof(buf1));

	ListView_GetItemText(hwndList, lp2, lParamSort, buf2, sizeof(buf2));

    if(SortData.iUPDOWN == UP)
        return(stricmp(buf1, buf2));
    else
        return(stricmp(buf1, buf2) * -1);
}
</code></pre>
<p>Danke für deine Hilfe auf jeden Fall.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1301360</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1301360</guid><dc:creator><![CDATA[dadevelopa]]></dc:creator><pubDate>Fri, 08 Jun 2007 13:56:29 GMT</pubDate></item></channel></rss>