Hi, I've discovered a possible bug in ListView.cs.
When a ColumnHeader is added to the ColumnHeaderList its 'owner' member is not set. The attached patch fixes this, although I'm not sure if it fixes it in the correct way. The attached TestCode.cs shows this and it also shows a bug where the neither the listview control nor the label control are redrawn when switching between the two tabPages. I'm not sure if this is supposed to work; if not, then sorry about bringing it up! There is also a curious anomaly in the MS documentation for "ListView.ColumnHeaderCollection.AddRange" which states that "This method removes all existing column headers from the collection before inserting new items". However, this does not seem to be true (in MS or Mono). Chris
ListViewFix.diff
Description: Binary data
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace TabControlTest1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after
InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#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>
private void InitializeComponent()
{
this.tabControl1 = new
System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.listView1 = new System.Windows.Forms.ListView();
this.label1 = new System.Windows.Forms.Label();
this.columnHeader1 = new
System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new
System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new
System.Windows.Forms.ColumnHeader();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Dock =
System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(0,
0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(552,
380);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.listView1);
this.tabPage1.Location = new System.Drawing.Point(4,
22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(544, 354);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
//
// tabPage2
//
this.tabPage2.Controls.Add(this.label1);
this.tabPage2.Location = new System.Drawing.Point(4,
22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(544, 354);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
//
// listView1
//
this.listView1.Columns.AddRange(new
System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3});
this.listView1.Dock =
System.Windows.Forms.DockStyle.Fill;
this.listView1.Location = new System.Drawing.Point(0,
0);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(544, 354);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
//
// label1
//
this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
this.label1.Location = new System.Drawing.Point(0, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(544, 354);
this.label1.TabIndex = 0;
this.label1.Text = "label1";
//
// columnHeader1
//
this.columnHeader1.Width = 100;
//
// columnHeader2
//
this.columnHeader2.Width = 100;
//
// columnHeader3
//
this.columnHeader3.Width = 100;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(552, 380);
this.Controls.Add(this.tabControl1);
this.Name = "Form1";
this.Text = "Form1";
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
}
