Просмотр исходного кода

listview column enhancements

svn path=/trunk/mcs/; revision=18808
Jordi Mas i Hernandez 22 лет назад
Родитель
Сommit
fcbd18e5ed

+ 1 - 1
mcs/class/System.Drawing/System.Drawing/impl/wine/win32Structs.cs

@@ -668,7 +668,7 @@ namespace System.Drawing.Win32Impl {
 		internal NMHDR   hdr;
 		internal int     iItem;
 		internal int     iButton;
-		internal HDITEM  hItem;
+		internal IntPtr  pitem;
 	}
 	#endregion
 

+ 134 - 120
mcs/class/System.Windows.Forms/System.Windows.Forms.Test/ListViewItemSimpleForm1.cs

@@ -1,5 +1,10 @@
 //
-// Use
+// Test application for the ListView class implementation
+//
+// Author:
+//   Jordi Mas i Hernàndez, [email protected]
+//	
+
 
 using System;
 using System.Collections;
@@ -8,7 +13,6 @@ using System.Drawing;
 
 
 
-
 public class MyListViewForm : System.Windows.Forms.Form
 {
 	ColumnHeader	column1 = null;
@@ -17,21 +21,51 @@ public class MyListViewForm : System.Windows.Forms.Form
 	ColumnHeader	column4 = null;
 	myListView listViewCtrl = null;
 	ListView.SelectedListViewItemCollection sel = null;
+	int nColInserted = 100;
 	
 	public static void Main(string[] args)
 	{
 		Application.Run(new MyListViewForm());
 	}
 	
-	public void ClearButton()
+	// Clear all columns
+	public void ClearColumnsButton()
+	{
+		listViewCtrl.Columns.Clear();
+	}
+	
+	public void ShowColumnsButton()
+	{
+		string sTxt = "";
+		// How the elements are order once an element in deleted
+		for (int i=0; i < listViewCtrl.Columns.Count; i++)
+			sTxt+=("Column: \"" +  listViewCtrl.Columns[i].Text + "\" idx: " + listViewCtrl.Columns[i].Index + " witdh:"+listViewCtrl.Columns[i].Width + "\r");				
+			
+		MessageBox.Show(sTxt);
+	}
+	
+	
+	public void AddColumnsButton()
 	{		
+		string sColText;		
+		sColText = "Column " + nColInserted;					
+		
+		Console.WriteLine ("AddColumnsButton->" + sColText);
+		
+		listViewCtrl.Columns.Insert(0, sColText, 150, HorizontalAlignment.Left);		
+		nColInserted++;		
+	}
+	
+	public void ClearButton()
+	{	
+			
 		Console.WriteLine ("MyListViewForm.Clear");				
 		listViewCtrl.Clear();		
 		
 		// How the elements are order once an element in deleted
 		for (int i=0; i < listViewCtrl.Columns.Count; i++)
 			Console.WriteLine ("Column " +  listViewCtrl.Columns[i].Text + " idx: " + listViewCtrl.Columns[i].Index);		
-		
+					
 		// Items
 		for (int i=0; i < listViewCtrl.Items.Count; i++)
 			Console.WriteLine ("Item->" +  listViewCtrl.Items[i].Text + " idx: " + listViewCtrl.Items[i].Index);
@@ -44,12 +78,7 @@ public class MyListViewForm : System.Windows.Forms.Form
 	
 	public void DelColumnButton()
 	{				
-		listViewCtrl.Columns.RemoveAt(2);
-		
-		// How the elements are order once an element in deleted
-		for (int i=0; i < listViewCtrl.Columns.Count; i++)
-			Console.WriteLine ("Column " +  listViewCtrl.Columns[i].Text + " idx: " + listViewCtrl.Columns[i].Index);		
-		
+		listViewCtrl.Columns.RemoveAt(1); /*Base on 0 index*/		
 	}
 	
 	public void DumpSelButton()
@@ -96,6 +125,7 @@ public class MyListViewForm : System.Windows.Forms.Form
 		Console.WriteLine ("ForeColor " + listViewCtrl.ForeColor);				
 		Console.WriteLine ("BackColor " + listViewCtrl.BackColor);						
 		Console.WriteLine ("ItemActivation " + listViewCtrl.Activation);				
+		Console.WriteLine ("ColumnHeaderStyle " + listViewCtrl.HeaderStyle);				
 		
 				
 	}
@@ -111,6 +141,8 @@ public class MyListViewForm : System.Windows.Forms.Form
 		
 		ShowClassDefaults();
 		
+		listViewCtrl.HeaderStyle = ColumnHeaderStyle.None;
+		
 		// Set params
 		listViewCtrl.View = View.Details;			
 		//listViewCtrl.LabelEdit = true;			
@@ -130,17 +162,19 @@ public class MyListViewForm : System.Windows.Forms.Form
     	ListViewItem item7 = new ListViewItem("item7");
     	ListViewItem item8 = new ListViewItem("item8");
     	ListViewItem item9 = new ListViewItem("item9");
-    	ListViewItem item10 = new ListViewItem("item10");
-    	
-   	    column1 = listViewCtrl.Columns.Add("Column 1", 100, HorizontalAlignment.Left);
-   	   	column2 =  listViewCtrl.Columns.Add("Column 2", 75, HorizontalAlignment.Right);
+    	ListViewItem item10 = new ListViewItem("item10 aaaaaaaaaaaaaaaaaaaaaaaaa");
+
+		Console.WriteLine ("*Column 1");			    	
+   	    column1 = listViewCtrl.Columns.Add("Column 1", -1, HorizontalAlignment.Left);
+   	    Console.WriteLine ("*Column 2");			    	
+   	   	column2 =  listViewCtrl.Columns.Add("Column 2", -2, HorizontalAlignment.Right);
    	   	column3 =  listViewCtrl.Columns.Add("Column 3", 50, HorizontalAlignment.Right);
    	   	column4 =  new ColumnHeader();
    	   	
    	   	column4.Text="Column 4";
    	   	column4.Width= 150;
    	   	
-   	   	listViewCtrl.Columns.AddRange(new ColumnHeader[]{column4});
+   	   	//listViewCtrl.Columns.AddRange(new ColumnHeader[]{column4});
    	    
 		listViewCtrl.Items.Add(item1);					
 		listViewCtrl.Items.Add(item2);					
@@ -160,6 +194,30 @@ public class MyListViewForm : System.Windows.Forms.Form
 		button.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
 		Controls.Add(button); 
 		
+		ClearColumnsButton button5 = new ClearColumnsButton(this);		
+		button5.Location = new System.Drawing.Point(115, 10);
+		button5.Name = "button5";
+		button5.Size = new System.Drawing.Size(100, 30);		
+		button5.Text = "Clear Columns";
+		button5.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
+		Controls.Add(button5); 		
+		
+		AddColumnsButton button6 = new AddColumnsButton(this);		
+		button6.Location = new System.Drawing.Point(225, 10);
+		button6.Name = "button6";
+		button6.Size = new System.Drawing.Size(100, 30);		
+		button6.Text = "Add Column";
+		button6.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
+		Controls.Add(button6); 		
+		
+		ShowColumnsButton button7 = new ShowColumnsButton(this);		
+		button7.Location = new System.Drawing.Point(335, 10);
+		button7.Name = "button7";
+		button7.Size = new System.Drawing.Size(100, 30);		
+		button7.Text = "Show Columns";
+		button7.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
+		Controls.Add(button7); 		
+		
 		DelItemButton button2 = new DelItemButton(this);		
 		button2.Location = new System.Drawing.Point(630, 90);
 		button2.Name = "button2";
@@ -184,114 +242,15 @@ public class MyListViewForm : System.Windows.Forms.Form
 		button4.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
 		Controls.Add(button4);    	
 		
-		/*
-		ClearButton button5 = new ClearButton(this);		
-		button4.Location = new System.Drawing.Point(630, 150);
-		button4.Name = "button4";
-		button4.Size = new System.Drawing.Size(100, 30);		
-		button4.Text = "Clear";
-		button4.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
-		Controls.Add(button4);    	*/
     	
     	Controls.Add(listViewCtrl);
 	}
 	
 	private void InitializeComponent()
-	{
-		
-		ClientSize = new System.Drawing.Size(750, 650);		
-		
-		ColumnSample();
-		
-		return;
-		
-	Console.WriteLine ("InitializeComponent()");
-
-    // Create a new ListView control.
-    ListView listView1 = new ListView();
-    listView1.Bounds = new Rectangle(new Point(10,10), new Size(300,200));
-
-    // Set the view to show details.
-    //listView1.View = View.Details;
-    // Allow the user to edit item text.
-    //listView1.LabelEdit = true;
-    // Allow the user to rearrange columns.
-    //listView1.AllowColumnReorder = true;
-    // Display check boxes.
-    //listView1.CheckBoxes = true;
-    // Select the item and subitems when selection is made.
-    //listView1.FullRowSelect = true;
-    // Display grid lines.
-    //listView1.GridLines = true;
-    // Sort the items in the list in ascending order.
-    //((listView1.Sorting = SortOrder.Ascending;
-    
-                
-    // Create three items and three sets of subitems for each item.
-    //ListViewItem item1 = new ListViewItem("item1",0);
-    ListViewItem item1 = new ListViewItem("item1");
-    // Place a check mark next to the item.
-    
-    // Create columns for the items and subitems.
-    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
-    //listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
-
-
-    //Add the items to the ListView.
-    //listView1.Items.AddRange(new ListViewItem[]{item1});
-    listView1.Items.Add(item1);
-    
-    //item1.Checked = true;
-    item1.SubItems.Add("1");        
-    //item1.SubItems.Add("2");
-    //item1.SubItems.Add("3");    
-       
-    //Console.WriteLine ("fi InitializeComponent()" + item1.ListView);
-    
-    
-    //Controls.Add(listView1);
-    Controls.Add(listView1);
-  	Console.WriteLine ("fi InitializeComponent()");
-    
-    return;
-    
-    ListViewItem item2 = new ListViewItem("item2",1);
-    item2.SubItems.Add("4");
-    item2.SubItems.Add("5");
-    item2.SubItems.Add("6");
-    ListViewItem item3 = new ListViewItem("item3",0);
-    // Place a check mark next to the item.
-    item3.Checked = true;
-    item3.SubItems.Add("7");
-    item3.SubItems.Add("8");
-    item3.SubItems.Add("9");
-
-    // Create columns for the items and subitems.
-    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
-    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
-    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left);
-    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center);
-
-    //Add the items to the ListView.
-            listView1.Items.AddRange(new ListViewItem[]{item1,item2,item3});
-
-    // Create two ImageList objects.
-    ImageList imageListSmall = new ImageList();
-    ImageList imageListLarge = new ImageList();
-
-    // Initialize the ImageList objects with bitmaps.
-    /*imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage1.bmp"));
-    imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage2.bmp"));
-    imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage1.bmp"));
-    imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage2.bmp"));*/
-
-    //Assign the ImageList objects to the ListView.
-    listView1.LargeImageList = imageListLarge;
-    listView1.SmallImageList = imageListSmall;
-
-    // Add the ListView to the control collection.
-    Controls.Add(listView1);
-    
+	{		
+		ClientSize = new System.Drawing.Size(750, 650);				
+		ColumnSample();		
+		return;   
 	}
 }
 
@@ -346,6 +305,62 @@ public class DumpSelButton : System.Windows.Forms.Button{
 		}
 }
 
+
+// Show columns
+public class ShowColumnsButton : System.Windows.Forms.Button{
+		MyListViewForm form = null;
+
+		public ShowColumnsButton(MyListViewForm frm) : base()
+		{
+			form =  frm;
+			
+		}
+		
+		/* User clicks the button*/
+		protected override void OnClick(EventArgs e) 
+		{	
+			form.ShowColumnsButton();
+		}
+}
+
+
+
+// ClearColumnsButton
+public class ClearColumnsButton : System.Windows.Forms.Button{
+		MyListViewForm form = null;
+
+		public ClearColumnsButton(MyListViewForm frm) : base()
+		{
+			form =  frm;
+			
+		}
+		
+		/* User clicks the button*/
+		protected override void OnClick(EventArgs e) 
+		{	
+			form.ClearColumnsButton();
+		}
+}
+
+
+// AddColumnsButton
+public class AddColumnsButton : System.Windows.Forms.Button{
+		MyListViewForm form = null;
+
+		public AddColumnsButton(MyListViewForm frm) : base()
+		{
+			form =  frm;
+			
+		}
+		
+		/* User clicks the button*/
+		protected override void OnClick(EventArgs e) 
+		{	
+			form.AddColumnsButton();
+		}
+}
+
+
 // ClearButton
 public class ClearButton : System.Windows.Forms.Button{
 		MyListViewForm form = null;
@@ -390,8 +405,7 @@ public class myListView : System.Windows.Forms.ListView
 		
 		protected override  void  OnItemActivate(EventArgs ice){
 			
-			Console.WriteLine ("OnItemActivate");					
-			
+			Console.WriteLine ("OnItemActivate");						
 			
 		}
 			

+ 2 - 3
mcs/class/System.Windows.Forms/System.Windows.Forms/ColumnHeader.cs

@@ -33,7 +33,7 @@ namespace System.Windows.Forms {
 		{
 			text = null;
 			textAlign = HorizontalAlignment.Left;
-			width = -2;//default to autosize, not in spec
+			width = -2;
 			index = -1;//default to not in list
 		}
 		
@@ -55,8 +55,7 @@ namespace System.Windows.Forms {
 			get { return index; }
 		}		
 		
-		public ListView ListView 	//return parent control.
-		{	
+		public ListView ListView { 	//return parent control.		
 			get { return container; }			
 		}
 		

+ 165 - 90
mcs/class/System.Windows.Forms/System.Windows.Forms/ListView.cs

@@ -46,7 +46,8 @@ namespace System.Windows.Forms {
 		private	SelectedIndexCollection	selItemIndexs = null;
 		private CheckedListViewItemCollection chkItemCol = null;
 		private CheckedIndexCollection chkIndexCol = null;
-		private	ItemActivation	activation = ItemActivation.Standard; // todo: check default
+		private	ItemActivation	activation = ItemActivation.Standard; 
+		private ColumnHeaderStyle headerStyle = ColumnHeaderStyle.Clickable;
 				
 		
 		//
@@ -187,14 +188,10 @@ namespace System.Windows.Forms {
 				bGridLines = value; 
 			}
 		}
-		[MonoTODO]
+		
 		public ColumnHeaderStyle HeaderStyle {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//throw new NotImplementedException ();
-			}
+			get {return headerStyle; }
+			set {headerStyle = value;}			
 		}
 		[MonoTODO]
 		public bool HideSelection {
@@ -339,12 +336,8 @@ namespace System.Windows.Forms {
 			
 			if (!bInitialised) return;
 			
-			Win32.SendMessage(Handle, (int)ListViewMessages.LVM_DELETEALLITEMS, 0,0);
-						
-			// Delete all columns
-			int nRslt = 1;
-			for (int n=0;  nRslt!=0; n++)
-				nRslt = Win32.SendMessage(Handle, (int)ListViewMessages.LVM_DELETECOLUMN, 0,0);
+			Win32.SendMessage(Handle, (int)ListViewMessages.LVM_DELETEALLITEMS, 0,0);			
+			
 			
 		}
 		[MonoTODO]
@@ -402,6 +395,20 @@ namespace System.Windows.Forms {
 				if (AutoArrange) createParams.Style |= (int) ListViewFlags.LVS_AUTOARRANGE;
 				if (!bLabelWrap)  createParams.Style |= (int) ListViewFlags.LVS_NOLABELWRAP;
 				if (!bMultiSelect) createParams.Style |= (int) ListViewFlags.LVS_SINGLESEL;
+				
+				switch (headerStyle)
+				{
+					case ColumnHeaderStyle.Clickable:	// Default						
+						break;
+					case ColumnHeaderStyle.Nonclickable:
+						createParams.Style |= (int) ListViewFlags.LVS_NOSORTHEADER;
+						break;
+					case ColumnHeaderStyle.None:
+						createParams.Style |= (int) ListViewFlags.LVS_NOCOLUMNHEADER;
+						break;
+					default:	
+						break;				
+				}
 									
 				return createParams;
 			}		
@@ -544,7 +551,7 @@ namespace System.Windows.Forms {
 					throw new  InvalidEnumArgumentException();	// TODO: Is this ok?
 			}	
 			
-			Console.WriteLine("Sort value " + nRslt); 
+			//Console.WriteLine("Sort value " + nRslt); 
 			return nRslt;
 		}
 		
@@ -602,26 +609,27 @@ namespace System.Windows.Forms {
 		
 		// Inserts a column in the control
 		internal void InsertColumnInCtrl(ColumnHeader  column)
-		{			
-			if (!bInitialised) return;
+		{	
+			if (!bInitialised) return;	
 			
-			LVCOLUMN lvc = new LVCOLUMN();					
+			LVCOLUMN lvc = new LVCOLUMN();				
+			bool bAutoSizing = false;	
+			int iCol;
 			
-			Console.WriteLine("Insert columns " + column.Text + " pos: " + column.Index+ " serial: "+  column.Serial);    						
+			Console.WriteLine("Insert columns " + column.Text + " pos: " + column.Index+ " serial: "+  column.Serial+ " autosizing " + bAutoSizing);    						
 					
 			lvc.mask = (int)( ListViewColumnFlags.LVCF_FMT | ListViewColumnFlags.LVCF_WIDTH | ListViewColumnFlags.LVCF_TEXT | ListViewColumnFlags.LVCF_SUBITEM);
 			lvc.iSubItem = column.Serial;
 			lvc.pszText = column.Text;
 			lvc.cx = column.Width;
-			lvc.fmt = TextAlign(column.TextAlign);			
-		
+			lvc.fmt = TextAlign(column.TextAlign);									
+			
 			IntPtr lvcBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(lvc));
   			Marshal.StructureToPtr(lvc, lvcBuffer, false);			
-  			Win32.SendMessage(Handle, (int)ListViewMessages.LVM_INSERTCOLUMNA, lvc.iSubItem, lvcBuffer);
-  			Marshal.FreeHGlobal(lvcBuffer);
+  			iCol = (int) Win32.SendMessage(Handle, (int)ListViewMessages.LVM_INSERTCOLUMNA, column.Index, lvcBuffer);
+  			Marshal.FreeHGlobal(lvcBuffer);			
   			
 		}	
-		
 		// Inserts an item in the control
 		internal void InsertItemInCtrl(ListViewItem listViewItem)
 		{			
@@ -672,12 +680,12 @@ namespace System.Windows.Forms {
 		}
 		
 		// Remove a column from the control
-		internal void RemoveColumnInCtrl(int nIndex){	
+		internal int DeleteColumnInCtrl(int nIndex){	
 			
-			if (!bInitialised) return;
+			if (!bInitialised) return 0;
 					
 			Console.WriteLine("Delete column " + nIndex);    											
-  			Win32.SendMessage(Handle, (int)ListViewMessages.LVM_DELETECOLUMN, nIndex, 0);  			
+  			return Win32.SendMessage(Handle, (int)ListViewMessages.LVM_DELETECOLUMN, nIndex, 0);  			
 		}				
 		
 		// Get the check status of an item						
@@ -726,8 +734,20 @@ namespace System.Windows.Forms {
 			
 			if (!bInitialised) return;					
 			Win32.SendMessage(Handle, (int)ListViewMessages.LVM_SETBKCOLOR, 0, 	(int) (backColor.R | backColor.G<<8 | backColor.B <<16));  			
-		}					
+		}				
 		
+		public void insertItemsInCtrl()	{
+			
+			Win32.SendMessage(Handle, (int)ListViewMessages.LVM_DELETEALLITEMS, 0,0);			
+		
+			for (int i=0; i<Items.Count; i++){	// Insert items		
+					
+				InsertItemInCtrl(Items[i]);							 						   								
+				
+				for (int s=0; s<Items[i].SubItems.Count; s++)	// Insert subitems		
+					SetItemInCtrl(Items[i].SubItems[s], s+1);
+			}						
+		}
 		
 		//						
 		protected override void WndProc(ref Message m) 	{			
@@ -747,14 +767,17 @@ namespace System.Windows.Forms {
 				for (int i=0; i<Columns.Count; i++)	// Insert columns
 					InsertColumnInCtrl(Columns[i]);							
 					
-				for (int i=0; i<Items.Count; i++){	// Insert items		
-						
-					InsertItemInCtrl(Items[i]);							 						   								
-					
-					for (int s=0; s<Items[i].SubItems.Count; s++)	// Insert subitems		
-						SetItemInCtrl(Items[i].SubItems[s], s+1);
-				}						
+				insertItemsInCtrl();					
 				
+				// We need to setup the column autoresizing flags after all the columns and items
+				// are inserted
+				for (int i=0; i<Columns.Count; i++)	{							
+					
+					if (Columns[i].Width!=-1 && Columns[i].Width!=-2) continue;																
+									
+					Win32.SendMessage(Handle, (int)ListViewMessages.LVM_SETCOLUMNWIDTH, Columns[i].Index, 	
+						Columns[i].Width);	
+				}
 			}
 			
 			
@@ -840,7 +863,7 @@ namespace System.Windows.Forms {
 					}
 					
 					case (int)ListViewNotifyMsg.LVN_ITEMCHANGED:					
-					{				
+					{			
 						
 						NMLISTVIEW NmLstView = (NMLISTVIEW)Marshal.PtrToStructure (m.LParam,	typeof (NMLISTVIEW));								
 						
@@ -867,12 +890,29 @@ namespace System.Windows.Forms {
 							{
 								chkItemCol.Add(i);
 								Console.WriteLine("Item checked " + i);    											
-							}
-						
+							}						
 						
 						break;
 					}
 					
+					
+					// Note: Under WinXP we get HDN_ITEMCHANGEDW
+					// seems that we change this using LVM_SETUNICODEFORMAT										
+					case (int)HeaderCtrlNOtify.HDN_ITEMCHANGEDA:
+					case (int)HeaderCtrlNOtify.HDN_ITEMCHANGEDW:
+					{							
+						
+						NMHEADER NmHeader = (NMHEADER)Marshal.PtrToStructure (m.LParam,	typeof (NMHEADER));																																		
+						HDITEM HDItem = (HDITEM)Marshal.PtrToStructure(NmHeader.pitem,	typeof (HDITEM));						
+						
+						if (((uint)HDItem.mask & (uint)HeaderItemFlags.HDI_HEIGHT)==(uint)HeaderItemFlags.HDI_HEIGHT)
+						{
+							Console.WriteLine("HDN_ITEMCHANGED item:" + NmHeader.iItem + " width: "  +HDItem.cxy); 							
+							Columns[NmHeader.iItem].Width = HDItem.cxy;
+						}
+												   																										
+						break;	
+					}
 											
 					default:
 						break;
@@ -1223,7 +1263,7 @@ namespace System.Windows.Forms {
 		{						
 			private ListView container = null;
 			private ArrayList collection = new ArrayList();	
-			private	int	nUniqueSerial = 5000; // TODO: Change to 0
+			private	int	nUniqueSerial = 5000;
 
 			//
 			//  --- Constructor
@@ -1247,26 +1287,47 @@ namespace System.Windows.Forms {
 				get { return (ColumnHeader) collection[index];}
 				set { collection[index] = value;}				
 			}
+						
+			//
+			//  --- Private methods used by the implementation
+			//			
+			public ColumnHeader FromSerial(int nSerial)
+			{
+				for (int i=0; i < collection.Count; i++){
+					ColumnHeader col = (ColumnHeader)collection[i];					
+					if (col.Serial==nSerial) return col;					
+				}
+				
+				return null;
+			}
+			
+			// The indexes have to be re-calculated
+			public void ReIndexCollection() {
+				for (int i=0; i < collection.Count; i++)
+				{
+					ColumnHeader col = (ColumnHeader)collection[i];
+					col.CtrlIndex=i;				
+				}
+				container.insertItemsInCtrl(); 
+			}
 
 			//
 			//  --- Public Methods
 			//
 			
-			public virtual int Add(ColumnHeader column) {
+			public virtual int Add(ColumnHeader column) {								
 				
-				if (column.Width==-1 ||column.Width==-2) column.Width=100; // TODO: Fix				
 				column.Serial = nUniqueSerial;
+				column.CtrlIndex = Count;
 				collection.Add(column);				
-				return Count-1;
+				nUniqueSerial++;
+				
+				container.InsertColumnInCtrl(column);
+				return Count-1;				
 			}
 			
 			public virtual ColumnHeader Add(string s, int witdh, HorizontalAlignment align) {				
-				// TODO: Witdh is Set to -1 to autosize the column header to the size of the largest subitem text 
-				//in the column or -2 to autosize the column header to the size of the text of the column header.				
-				//if (witdh==-1 ||witdh==-2) throw new NotImplementedException();		
-				if (witdh==-1 ||witdh==-2) witdh=100; // TODO: Fix
-								
-				Console.WriteLine("ColumnHeader.Add " +  s);															
+				
 				ColumnHeader column = new ColumnHeader();		
 				
 				/* The zero-based index of the column header within the ListView.ColumnHeaderCollection of the ListView control it is contained in.*/
@@ -1275,33 +1336,44 @@ namespace System.Windows.Forms {
 				column.TextAlign = align;
 				column.Width = witdh;						
 				column.Container = container;
-				column.Serial = nUniqueSerial;
-				collection.Add(column);				
-				nUniqueSerial++;
+				column.Serial = nUniqueSerial;			
+				collection.Add(column);								
+				nUniqueSerial++;				
+				container.InsertColumnInCtrl(column);				
 				
 				return column;				
 			}
 			
 			public virtual void AddRange(ColumnHeader[] values) {
-				for (int i=0; i<values.Length; i++)
-					collection.Add(values[i]);	
+				for (int i=0; i<values.Length; i++)	{
+					Add(values[i]);						
+				}
 			}
 			
 			public void Clear() {
+				
+				// Delete all columns
+				int nRslt = 1;
+				for (int n=0;  nRslt!=0; n++)
+					nRslt = container.DeleteColumnInCtrl(0);
+				
 				collection.Clear();
-			}
+			}			
 			
-			[MonoTODO]
-			public bool Contains(ColumnHeader value) 
-			{
-				throw new NotImplementedException ();
+			public bool Contains(ColumnHeader value) {
+				return 	collection.Contains(value);			
 			}
-			[MonoTODO]
-			public override bool Equals(object obj) 
-			{
-				//FIXME:
-				return base.Equals(obj);
+			
+			public override bool Equals(object obj) {
+				
+				if(obj!= null && obj is ColumnHeaderCollection)	{
+					ColumnHeaderCollection that = (ColumnHeaderCollection)obj;
+					return (this.collection == that.collection);
+				}
+				
+				return false;
 			}
+			
 			[MonoTODO]
 			public override int GetHashCode() 
 			{
@@ -1316,46 +1388,43 @@ namespace System.Windows.Forms {
 			public int IndexOf(ColumnHeader value) {
 				return collection.IndexOf(value);
 			}
-			[MonoTODO]
-			public void Insert(int witdh, ColumnHeader value) {
-				//FIXME:
-			}
-			[MonoTODO]
-			public void Insert(int val1, string str, int val2, HorizontalAlignment align) 
-			{
-				//FIXME:
+			
+			public void Insert(int index, ColumnHeader column) { 
+								
+				column.Serial = nUniqueSerial;								
+				column.CtrlIndex = index;
+				collection.Insert(index, column);				
+				nUniqueSerial++;
+				container.InsertColumnInCtrl(column);
+				ReIndexCollection();
 			}
 			
-			public virtual void Remove(ColumnHeader value) 
-			{
+			public void Insert(int index, string str, int witdh, HorizontalAlignment align) {
+				
+				ColumnHeader column = new ColumnHeader();									
+
+				column.Text = str;
+				column.TextAlign = align;
+				column.Width = witdh;						
+				column.Container = container;
+				Insert(index, column);								
 				
 			}
 			
-			public ColumnHeader FromSerial(int nSerial)
-			{
-				for (int i=0; i < collection.Count; i++)
-				{
-					ColumnHeader col = (ColumnHeader)collection[i];					
-					if (col.Serial==nSerial) return col;					
-				}
-				
-				return null;
+			public virtual void Remove(ColumnHeader value) 	{
+				RemoveAt(value.Index);
 			}
+					
 			
 			public virtual void RemoveAt(int index) 
 			{					
 				if (index>=Count) 				
 					throw new ArgumentOutOfRangeException("Invalid value for array index");											
 				
-				container.RemoveColumnInCtrl(index); 
+				container.DeleteColumnInCtrl(index); 
 				collection.Remove(collection[index]);				
 				
-				// The indexes have to be re-calculated
-				for (int i=0; i < collection.Count; i++)
-				{
-					ColumnHeader col = (ColumnHeader)collection[i];
-					col.CtrlIndex=i;				
-				}
+				ReIndexCollection();
 			}
 			
 			/// <summary>
@@ -1436,6 +1505,8 @@ namespace System.Windows.Forms {
 				//FIXME:
 			}
 			// End Of ICollection
+			
+			
 		}
 		//
 		// System.Windows.Forms.ListView.ListViewItemCollection.cs
@@ -1485,7 +1556,8 @@ namespace System.Windows.Forms {
 				Console.WriteLine("ListViewItem.Add " +  item.Text + " idx: " + item.Index);											
 				
 				item.CtrlIndex = Count;				
-				int nIdx = collection.Add(item);				
+				container.InsertItemInCtrl(item);		
+				int nIdx = collection.Add(item);						
 				return (ListViewItem)collection[nIdx];
 				
 			}
@@ -1501,7 +1573,10 @@ namespace System.Windows.Forms {
 			public void AddRange(ListViewItem[] values) {
 				
 				for (int i=0; i<values.Length; i++)
+				{
+					container.InsertItemInCtrl(values[i]);
 					Add(values[i]);	
+				}
 				
 			}
 			

+ 34 - 1
mcs/class/System.Windows.Forms/System.Windows.Forms/win32Enums.cs

@@ -1088,7 +1088,8 @@ namespace System.Windows.Forms{
 		LVM_DELETEALLITEMS      		= (LVM_FIRST + 9),
 		LVM_GETNEXTITEM         		= (LVM_FIRST + 12),
 		LVM_SETITEMCOUNT        		= (LVM_FIRST + 47),
-		LVM_GETITEMCOUNT        		= (LVM_FIRST + 4)
+		LVM_GETITEMCOUNT        		= (LVM_FIRST + 4),
+		LVM_SETCOLUMNWIDTH          	= (LVM_FIRST + 30)
 	}
 	#endregion
 
@@ -3104,4 +3105,36 @@ namespace System.Windows.Forms{
 		LVN_ODSTATECHANGED		= (LVN_FIRST-15)
 	}
 	
+	public enum ListViewColumnWithMsg: int 
+	{	
+		LVSCW_AUTOSIZE          	=  -1,
+		LVSCW_AUTOSIZE_USEHEADER  	=  -2
+	}
+	
+	public enum HeaderCtrlNOtify: int 
+	{	
+		HDN_FIRST				= (0-300),
+		HDN_LAST				= (0-399),
+		HDN_ITEMCHANGINGA		= (HDN_FIRST-0),
+		HDN_ITEMCHANGINGW		= (HDN_FIRST-20),
+		HDN_ITEMCHANGEDA		= (HDN_FIRST-1),
+		HDN_ITEMCHANGEDW		= (HDN_FIRST-21),
+		HDN_ITEMCLICKA			= (HDN_FIRST-2),
+		HDN_ITEMCLICKW			= (HDN_FIRST-22),
+		HDN_ITEMDBLCLICKA		= (HDN_FIRST-3),
+		HDN_ITEMDBLCLICKW		= (HDN_FIRST-23),
+		HDN_DIVIDERDBLCLICKA	= (HDN_FIRST-5),
+		HDN_DIVIDERDBLCLICKW	= (HDN_FIRST-25),
+		HDN_BEGINTRACKA			= (HDN_FIRST-6),
+		HDN_BEGINTRACKW			= (HDN_FIRST-26),
+		HDN_ENDTRACKA			= (HDN_FIRST-7),
+		HDN_ENDTRACKW			= (HDN_FIRST-27),
+		HDN_TRACKA				= (HDN_FIRST-8),
+		HDN_TRACKW				= (HDN_FIRST-28),
+		HDN_GETDISPINFOA		= (HDN_FIRST-9),
+		HDN_GETDISPINFOW		= (HDN_FIRST-29),
+		HDN_BEGINDRAG			= (HDN_FIRST-10),
+		HDN_ENDDRAG				= (HDN_FIRST-11)
+	}
+	
 }

+ 1 - 1
mcs/class/System.Windows.Forms/System.Windows.Forms/win32Structs.cs

@@ -719,7 +719,7 @@ namespace System.Windows.Forms
 		internal NMHDR   hdr;
 		internal int     iItem;
 		internal int     iButton;
-		internal HDITEM  hItem;
+		internal IntPtr  pitem;
 	}
 	#endregion