B
Boris
Hi folks!
Look at the code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace LstView
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader ch1;
private System.Windows.Forms.ColumnHeader ch2;
private System.Windows.Forms.ColumnHeader ch3;
/// <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
//
InitListView();
}
/// <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.listView1 = new System.Windows.Forms.ListView();
this.ch1 = new System.Windows.Forms.ColumnHeader();
this.ch2 = new System.Windows.Forms.ColumnHeader();
this.ch3 = new System.Windows.Forms.ColumnHeader();
this.SuspendLayout();
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.ch1,
this.ch2,
this.ch3});
this.listView1.HeaderStyle =
System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listView1.Location = new System.Drawing.Point(16, 24);
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.listView1.Size = new System.Drawing.Size(256, 224);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.SelectedIndexChanged += new
System.EventHandler(this.listView1_SelectedIndexChanged);
//
// ch1
//
this.ch1.Text = "ch1";
//
// ch2
//
this.ch2.Text = "ch2";
//
// ch3
//
this.ch3.Text = "ch3";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.listView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void InitListView()
{
string [] item1=new string[3];
item1[0]="start";
item1[1]="end";
item1[2]="free";
ListViewItem lvi = new ListViewItem(item1);
listView1.Items.Add(lvi);
}
private void listView1_SelectedIndexChanged(object sender, System.EventArgs
e)
{
foreach(ListViewItem lvi in listView1.ListViewItemCollection)
{
}
}
}
}
I know that listView1 have Items property of type ListViewItemCollection,
but if I by mistake wrote ListViewItemCollection why compiler should stuck?
Look at the code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace LstView
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader ch1;
private System.Windows.Forms.ColumnHeader ch2;
private System.Windows.Forms.ColumnHeader ch3;
/// <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
//
InitListView();
}
/// <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.listView1 = new System.Windows.Forms.ListView();
this.ch1 = new System.Windows.Forms.ColumnHeader();
this.ch2 = new System.Windows.Forms.ColumnHeader();
this.ch3 = new System.Windows.Forms.ColumnHeader();
this.SuspendLayout();
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.ch1,
this.ch2,
this.ch3});
this.listView1.HeaderStyle =
System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listView1.Location = new System.Drawing.Point(16, 24);
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
this.listView1.Size = new System.Drawing.Size(256, 224);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.SelectedIndexChanged += new
System.EventHandler(this.listView1_SelectedIndexChanged);
//
// ch1
//
this.ch1.Text = "ch1";
//
// ch2
//
this.ch2.Text = "ch2";
//
// ch3
//
this.ch3.Text = "ch3";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.listView1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void InitListView()
{
string [] item1=new string[3];
item1[0]="start";
item1[1]="end";
item1[2]="free";
ListViewItem lvi = new ListViewItem(item1);
listView1.Items.Add(lvi);
}
private void listView1_SelectedIndexChanged(object sender, System.EventArgs
e)
{
foreach(ListViewItem lvi in listView1.ListViewItemCollection)
{
}
}
}
}
I know that listView1 have Items property of type ListViewItemCollection,
but if I by mistake wrote ListViewItemCollection why compiler should stuck?