Home > Back-end >  Single column headings, listview automatic sorting
Single column headings, listview automatic sorting

Time:10-26

Which great god to look at the listview sorting problem,
//processing click message
Case WM_NOTIFY:
LParam NMHDR * pNMHDR=(NMHDR *);
Listview=GetDlgItem (hWnd IDC_LIST1);
If (pNMHDR - & gt; Code==LVN_COLUMNCLICK)

{
//LPNMLISTVIEW pNMLV=reinterpret_cast & lt; LPNMLISTVIEW> (pNMHDR);
PNMHDR NMLISTVIEW * pNMListView=(NMLISTVIEW *);
ListView_SortItems (listview, CompareFunc, (LPARAM) pNMListView - & gt; The iSubItem);
If (sort_type==false)
Sort_type=true;
The else
Sort_type=false;
break;
}
//callback function to write
Int the CALLBACK CompareFunc (LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)

{
The static TCHAR szBuf1 [50], szBuf2 [50];
Int ret.
ListView_GetItemText (listview, lParam1 lParamSort szBuf1, 50);
ListView_GetItemText (listview, lParam2 lParamSort szBuf2, 50);

If (sort_type)
{
Ret=LSTRCMP (szBuf1 szBuf2);
}
The else
{
Ret=- LSTRCMP (szBuf1 szBuf2);
}
Return ret.

}
//add the content into the listview
LVITEMA item1
The Info Info [4];//define a structure, the mid-term only a TCHAR s1 [max_path];
ZeroMemory (& amp; Info, sizeof (info)/sizeof (info));
HWND list1=GetDlgItem (HWND IDC_LIST1);//handle to get the listview
ZeroMemory (& amp; Item1, sizeof (item1)/sizeof (LVITEMA));
Int ItemCount=ListView_GetItemCount (list1);//get the listview lines
Item1. Mask=LVIF_TEXT | LVIF_PARAM;
Item1. ISubItem=0;
Item1. IItem=ItemCount;
Item1. PszText=info [0]. S1.
Int j=ListView_InsertItem (list1, & amp; Item1);
Item1. LParam=j;
For (int I=1; i<4. I++)
{

Item1. ISubItem=I;
ListView_SetItemText (list1, j, I, the info [I]. S1).
}

CodePudding user response:

Click the scheduling problems about listview
Look back I send you a piece of code before
Using the STL standard library

CodePudding user response:

Ok, thanks first, my qq: 343379173

CodePudding user response:

 
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

# include & lt; The VCL. H>
# pragma hdrstop

# include "Unit1. H"
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# pragma package (smart_init)
# pragma resource "*. DFM
"TForm1 * Form1;
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
__fastcall TForm1: : TForm1 (TComponent * Owner)
: TForm (the Owner)
{
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Void __fastcall TForm1: : ListView1ColumnClick (TObject * Sender, TListColumn * Column)
{
Int I, m, n, j;
The static bool od=true;
Const AnsiString Captions1 [4]={" name ", "gender", "native", "degree"};
for(int i=0; iListView1 - & gt; The Columns - & gt; The Items [I] - & gt; Caption=Captions1 [I];
Od=! Od;
N=the Column - & gt; The Index;
M=ListView1 - & gt; The Items - & gt; The Count.
If (od)
{
The Column - & gt; Caption=Column - & gt; Caption + "delta";
}
The else
The Column - & gt; Caption=Column - & gt; Caption + "del";

ListView1 - & gt; The Items - & gt; The Add ();
If (n==0)
{
for(i=0; iFor (j=I + 1; JIf (od)
{
If (ListView1 - & gt; The Items - & gt; The Item [I] - & gt; Caption & gt; ListView1 - & gt; The Items - & gt; The Item [j] - & gt; Caption)
{
ListView1 - & gt; The Items - & gt; The Item [m]=ListView1 - & gt; The Items - & gt; The Item [I];
ListView1 - & gt; The Items - & gt; The Item [I]=ListView1 - & gt; The Items - & gt; The Item [j];
ListView1 - & gt; The Items - & gt; The Item [j]=ListView1 - & gt; The Items - & gt; The Item [m];
}
}
The else
{
If (ListView1 - & gt; The Items - & gt; The Item [I] - & gt; Caption & lt; ListView1 - & gt; The Items - & gt; The Item [j] - & gt; Caption)
{
ListView1 - & gt; The Items - & gt; The Item [m]=ListView1 - & gt; The Items - & gt; The Item [I];
ListView1 - & gt; The Items - & gt; The Item [I]=ListView1 - & gt; The Items - & gt; The Item [j];
ListView1 - & gt; The Items - & gt; The Item [j]=ListView1 - & gt; The Items - & gt; The Item [m];
}
}
}
The else
{
for(i=0; iFor (j=I + 1; JIf (od)
{
If (sg (ListView1 - & gt; The Items - & gt; The Item [I] - & gt; SubItems - & gt; The Text, n - 1) & gt; Sg (ListView1 - & gt; The Items - & gt; The Item [j] - & gt; SubItems - & gt; The Text, n - 1))
{
ListView1 - & gt; The Items - & gt; The Item [m]=ListView1 - & gt; The Items - & gt; The Item [I];
ListView1 - & gt; The Items - & gt; The Item [I]=ListView1 - & gt; The Items - & gt; The Item [j];
ListView1 - & gt; The Items - & gt; The Item [j]=ListView1 - & gt; The Items - & gt; The Item [m];
}
}
The else
{
If (sg (ListView1 - & gt; The Items - & gt; The Item [I] - & gt; SubItems - & gt; The Text, n - 1) & lt; Sg (ListView1 - & gt; The Items - & gt; The Item [j] - & gt; SubItems - & gt; The Text, n - 1))
{
ListView1 - & gt; The Items - & gt; The Item [m]=ListView1 - & gt; The Items - & gt; The Item [I];
ListView1 - & gt; The Items - & gt; The Item [I]=ListView1 - & gt; The Items - & gt; The Item [j];
ListView1 - & gt; The Items - & gt; The Item [j]=ListView1 - & gt; The Items - & gt; The Item [m];
}
}
}
ListView1 - & gt; The Items - & gt; The Delete (m);
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
AnsiString TForm1: : sg (AnsiString STR, int n)
{
Int I, l;
AnsiString qq (STR);
L=qq. The Length (); nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related