Hey guys,

I'm trying to figure out a way to sort things in ListView. Eventually I'm going to want to add something along the lines of:

Name W L D Points
Joe 5 1 2 12
Bob 4 2 1 9

etc... and be able to sort on W, L, D, and Points.


I found this: http://support.microsoft.com/kb/816183 on the MSDN site and have been trying to implement it. I set up everything, change to /clrldSyntax the way it describes, and try compiling, and it doesn't want to work.

The errors are:

Code:
c:\documents and settings\chris d\my documents\visual studio 2005\projects\q816183\q816183\Form1.h(22) : error C2059: syntax error : 'public'
c:\documents and settings\chris d\my documents\visual studio 2005\projects\q816183\q816183\Form1.h(22) : error C2059: syntax error : 'public'
c:\documents and settings\chris d\my documents\visual studio 2005\projects\q816183\q816183\Form1.h(23) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\chris d\my documents\visual studio 2005\projects\q816183\q816183\Form1.h(23) : error C2447: '{' : missing function header (old-style formal list?)
.\Q816183.cpp(9) : error C2065: 'array' : undeclared identifier
.\Q816183.cpp(9) : error C2275: 'System::String' : illegal use of this type as an expression
.\Q816183.cpp(9) : error C2059: syntax error : '>'
.\Q816183.cpp(10) : error C2143: syntax error : missing ';' before '{'
.\Q816183.cpp(10) : error C2447: '{' : missing function header (old-style formal list?)
and Form1.h is below. Line 22 that it mentions is the line with public ref class Form 1 : ...

Code:
#pragma once
#include "ListViewColumnSorter.h"

namespace Q816183 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
    private: ListViewColumnSorter *lvwColumnSorter;
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
			// Create an instance of a ListView column sorter and assign it 
// to the ListView control.
lvwColumnSorter = new ListViewColumnSorter();
listView1->ListViewItemSorter = lvwColumnSorter;
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::ListView^  listView1;
	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->listView1 = (gcnew System::Windows::Forms::ListView());
			this->SuspendLayout();
			// 
			// listView1
			// 
			this->listView1->Location = System::Drawing::Point(67, 29);
			this->listView1->Name = L"listView1";
			this->listView1->Size = System::Drawing::Size(399, 345);
			this->listView1->TabIndex = 0;
			this->listView1->UseCompatibleStateImageBehavior = false;
			this->listView1->ColumnClick += gcnew System::Windows::Forms::ColumnClickEventHandler(this, &Form1::listView1_ColumnClick);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(568, 402);
			this->Controls->Add(this->listView1);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);

		}
#pragma endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {

				 ColumnHeader *columnheader;		// This is used for creating column headers.
ListViewItem *listviewitem;		// This is used to create ListView items.
listView1->Enabled = true;

// Make sure that the view is set to show details.
listView1->set_View(System::Windows::Forms::View::Details);


// Create some ListView items that include first and last names.
listviewitem = new ListViewItem("John");
listviewitem->SubItems->Add("Smith");
this->listView1->Items->Add(listviewitem);

listviewitem = new ListViewItem("Brian");
listviewitem->SubItems->Add("Lloyd");
this->listView1->Items->Add(listviewitem);

listviewitem = new ListViewItem("Kimberly");
listviewitem->SubItems->Add("Zimmerman");
this->listView1->Items->Add(listviewitem);

listviewitem = new ListViewItem("Tamara");
listviewitem->SubItems->Add("Johnson");
this->listView1->Items->Add(listviewitem);
						
// Create some column headers for the data. 
columnheader = new ColumnHeader();
columnheader->Text = "First Name";
this->listView1->Columns->Add(columnheader);

columnheader = new ColumnHeader();
columnheader->Text = "Last Name";
this->listView1->Columns->Add(columnheader);

// Loop through and size each column header to fit the column header text.
IEnumerator* iEnum = this->listView1->Columns->GetEnumerator();
while(iEnum->MoveNext())				
{

	ColumnHeader *ch;
	ch = __try_cast<ColumnHeader*>(iEnum->Current);
	ch->set_Width(-2);
}
			 }
	private: System::Void listView1_ColumnClick(System::Object^  sender, System::Windows::Forms::ColumnClickEventArgs^  e) {
				 // Determine if the clicked column is already the column that is being sorted.
if ( e->Column == lvwColumnSorter->SortColumn )
{
	// Reverse the current sort direction for this column.
	if (lvwColumnSorter->Order == SortOrder::Ascending)
	{
		lvwColumnSorter->Order = SortOrder::Descending;
	}
	else
	{
		lvwColumnSorter->Order = SortOrder::Ascending;
	}
}
else
{
	// Set the column number that is to be sorted. By default, this is in ascending order.
	lvwColumnSorter->SortColumn = e->Column;
	lvwColumnSorter->Order = SortOrder::Ascending;
}

// Perform the sort with these new sort options.
listView1->Sort();
			 }
};
}