static void Main()
{
Application.Run(new ListViewCountry());
}
private void ListViewCountry_Load(object sender, System.EventArgs e)
{
// Create an image list of icons that you want to display for each item
ig.Images.Add(new Icon("FLGUSA01.ICO"));
ig.Images.Add(new Icon("CTRITALY.ICO"));
ig.Images.Add(new Icon("FLGCAN.ICO"));
ig.Images.Add(new Icon("FLGSWITZ.ICO"));
ig.Images.Add(new Icon("FLGUK.ICO"));
// Set the Imagelist for SmallIcons
listView1.SmallImageList = ig ;
// Set the ImageList for LargeIcons
listView1.LargeImageList = ig ;
// Align the columns 1,2,3 and the column data as Center
listView1.Columns[1].TextAlign = HorizontalAlignment.Center ;
listView1.Columns[2].TextAlign = HorizontalAlignment.Center ;
listView1.Columns[3].TextAlign = HorizontalAlignment.Center ;
// Create a ListViewItem object for evey item that you wish to add the ListView.
string[] lv = new String[4];
lv[0] = "USA" ;
lv[1] = "Washington DC" ;
lv[2] = "New York" ;
lv[3] = "Los Angeles" ;
listView1.Items.Add( new ListViewItem(lv,0));
lv[0] = "Italy" ;
lv[1] = "Rome" ;
lv[2] = "Venice" ;
lv[3] = "Milan" ;
listView1.Items.Add( new ListViewItem(lv,1));
lv[0] = "Canada" ;
lv[1] = "Ottawa" ;
lv[2] = "Montreal" ;
lv[3] = "Quebec" ;
listView1.Items.Add( new ListViewItem(lv,2));
lv[0] = "Switzerland" ;
lv[1] = "Geneva" ;
lv[2] = "Zurich" ;
lv[3] = "Lucerne" ;
listView1.Items.Add( new ListViewItem(lv,3));
lv[0] = "UnitedKingdom" ;
lv[1] = "London" ;
lv[2] = "ChesterField" ;
lv[3] = "Wembly" ;
listView1.Items.Add( new ListViewItem(lv,4));
for ( int j=0; j < listView1.Items.Count ; j++)
{
ListViewItem lvi = listView1.Items[j] ;
for ( int i=0; i < lvi.SubItems.Count ; i++)
{
Console.Write(lvi.SubItems[i].Text + "\t") ;
}
Console.WriteLine("\n");
}
}
Reference
沒有留言:
張貼留言