ListView Country: image and font : ListView « GUI Windows Form « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » GUI Windows Form » ListViewScreenshots 
ListView Country: image and font
ListView Country: image and font

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace ListView
{
  /// <summary>
  /// Summary description for ListViewCountry.
  /// </summary>
  public class ListViewCountry : System.Windows.Forms.Form
  {
    private System.Windows.Forms.ListView listView1;
    private System.Windows.Forms.ColumnHeader Country;
    private System.Windows.Forms.ColumnHeader Capital;
    private System.Windows.Forms.ColumnHeader City_1;
    private System.Windows.Forms.ColumnHeader City_2;
    private System.Windows.Forms.Button REPORT;
    private System.Windows.Forms.Button LIST;
    private System.Windows.Forms.Button SMALLICON;
    private System.Windows.Forms.Button LARGEICON;
    ImageList ig = new ImageList();
    private System.Windows.Forms.Button SELECTED;
    private System.Windows.Forms.Button CHECKED;
    private System.Windows.Forms.Panel panel1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public ListViewCountry()
    {
      //
      // 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 Disposebool disposing )
    {
      ifdisposing )
      {
        if (components != null
        {
          components.Dispose();
        }
      }
      base.Disposedisposing );
    }

    #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.Country = new System.Windows.Forms.ColumnHeader();
         this.Capital = new System.Windows.Forms.ColumnHeader();
         this.City_1 = new System.Windows.Forms.ColumnHeader();
         this.City_2 = new System.Windows.Forms.ColumnHeader();
         this.REPORT = new System.Windows.Forms.Button();
         this.LIST = new System.Windows.Forms.Button();
         this.SMALLICON = new System.Windows.Forms.Button();
         this.LARGEICON = new System.Windows.Forms.Button();
         this.SELECTED = new System.Windows.Forms.Button();
         this.CHECKED = new System.Windows.Forms.Button();
         this.panel1 = new System.Windows.Forms.Panel();
         this.panel1.SuspendLayout();
         this.SuspendLayout();
         // 
         // listView1
         // 
         this.listView1.AllowColumnReorder = true;
         this.listView1.CheckBoxes = true;
         this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
                                                                                    this.Country,
                                                                                    this.Capital,
                                                                                    this.City_1,
                                                                                    this.City_2});
         this.listView1.Dock = System.Windows.Forms.DockStyle.Top;
         this.listView1.Font = new System.Drawing.Font("Microsoft Sans Serif"11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.listView1.ForeColor = System.Drawing.SystemColors.HotTrack;
         this.listView1.FullRowSelect = true;
         this.listView1.Name = "listView1";
         this.listView1.Size = new System.Drawing.Size(464152);
         this.listView1.TabIndex = 0;
         this.listView1.View = System.Windows.Forms.View.Details;
         this.listView1.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.listView1_ColumnClick);
         this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
         // 
         // Country
         // 
         this.Country.Text = "Country";
         this.Country.Width = 100;
         // 
         // Capital
         // 
         this.Capital.Text = "Capital";
         this.Capital.Width = 150;
         // 
         // City_1
         // 
         this.City_1.Text = "City_1";
         this.City_1.Width = 100;
         // 
         // City_2
         // 
         this.City_2.Text = "City_2";
         this.City_2.Width = 100;
         // 
         // REPORT
         // 
         this.REPORT.Dock = System.Windows.Forms.DockStyle.Left;
         this.REPORT.Location = new System.Drawing.Point(750);
         this.REPORT.Name = "REPORT";
         this.REPORT.Size = new System.Drawing.Size(7524);
         this.REPORT.TabIndex = 1;
         this.REPORT.Text = "Report";
         this.REPORT.Click += new System.EventHandler(this.REPORT_Click);
         // 
         // LIST
         // 
         this.LIST.Dock = System.Windows.Forms.DockStyle.Left;
         this.LIST.Location = new System.Drawing.Point(3000);
         this.LIST.Name = "LIST";
         this.LIST.Size = new System.Drawing.Size(7524);
         this.LIST.TabIndex = 1;
         this.LIST.Text = "List";
         this.LIST.Click += new System.EventHandler(this.LIST_Click);
         // 
         // SMALLICON
         // 
         this.SMALLICON.Dock = System.Windows.Forms.DockStyle.Left;
         this.SMALLICON.Location = new System.Drawing.Point(1500);
         this.SMALLICON.Name = "SMALLICON";
         this.SMALLICON.Size = new System.Drawing.Size(7524);
         this.SMALLICON.TabIndex = 1;
         this.SMALLICON.Text = "Small Icon";
         this.SMALLICON.Click += new System.EventHandler(this.SMALLICON_Click);
         // 
         // LARGEICON
         // 
         this.LARGEICON.Dock = System.Windows.Forms.DockStyle.Left;
         this.LARGEICON.Location = new System.Drawing.Point(3750);
         this.LARGEICON.Name = "LARGEICON";
         this.LARGEICON.Size = new System.Drawing.Size(7524);
         this.LARGEICON.TabIndex = 1;
         this.LARGEICON.Text = "Large Icon";
         this.LARGEICON.Click += new System.EventHandler(this.LARGEICON_Click);
         // 
         // SELECTED
         // 
         this.SELECTED.Dock = System.Windows.Forms.DockStyle.Left;
         this.SELECTED.Name = "SELECTED";
         this.SELECTED.Size = new System.Drawing.Size(7524);
         this.SELECTED.TabIndex = 2;
         this.SELECTED.Text = "Selected";
         this.SELECTED.Click += new System.EventHandler(this.SELECTED_Click);
         // 
         // CHECKED
         // 
         this.CHECKED.Dock = System.Windows.Forms.DockStyle.Left;
         this.CHECKED.Location = new System.Drawing.Point(2250);
         this.CHECKED.Name = "CHECKED";
         this.CHECKED.Size = new System.Drawing.Size(7524);
         this.CHECKED.TabIndex = 3;
         this.CHECKED.Text = "Checked";
         this.CHECKED.Click += new System.EventHandler(this.CHECKED_Click);
         // 
         // panel1
         // 
         this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                             this.LARGEICON,
                                                                             this.LIST,
                                                                             this.CHECKED,
                                                                             this.SMALLICON,
                                                                             this.REPORT,
                                                                             this.SELECTED});
         this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
         this.panel1.Location = new System.Drawing.Point(0157);
         this.panel1.Name = "panel1";
         this.panel1.Size = new System.Drawing.Size(46424);
         this.panel1.TabIndex = 4;
         // 
         // ListViewCountry
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(513);
         this.ClientSize = new System.Drawing.Size(464181);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.panel1,
                                                                      this.listView1});
         this.Name = "ListViewCountry";
         this.Text = "ListView";
         this.Load += new System.EventHandler(this.ListViewCountry_Load);
         this.panel1.ResumeLayout(false);
         this.ResumeLayout(false);

      }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    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.Addnew ListViewItem(lv,0));

      lv[0"Italy" ;
      lv[1"Rome" ;
      lv[2"Venice" ;
      lv[3"Milan" ;
      listView1.Items.Addnew ListViewItem(lv,1));

      lv[0"Canada" ;
      lv[1"Ottawa" ;
      lv[2"Montreal" ;
      lv[3"Quebec" ;
      listView1.Items.Addnew ListViewItem(lv,2));

      lv[0"Switzerland" ;
      lv[1"Geneva" ;
      lv[2"Zurich" ;
      lv[3"Lucerne" ;
      listView1.Items.Addnew ListViewItem(lv,3));

      lv[0"UnitedKingdom" ;
      lv[1"London" ;
      lv[2"ChesterField" ;
      lv[3"Wembly" ;
      listView1.Items.Addnew 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");
      }
    }

    private void REPORT_Click(object sender, System.EventArgs e)
    {
      // Switch to the Report View
      this.Text = "Report View";
      listView1.View = View.Details; 
    }

    private void LARGEICON_Click(object sender, System.EventArgs e)
    {
      // Switch to the LargeIcon view
      this.Text = "LargeIcon View";
      listView1.View = View.LargeIcon ; 
    }

    private void SMALLICON_Click(object sender, System.EventArgs e)
    {
      // Switch to the SmallIcon view
      this.Text = "SmallIcon View";
      listView1.View = View.SmallIcon; 
    }

    private void LIST_Click(object sender, System.EventArgs e)
    {
      // Switch to the List view
      this.Text = "List View";
      listView1.View = View.List; 
    }

    private void SELECTED_Click(object sender, System.EventArgs e)
    {
      // Get the list of indices for all the selected items

      string StrSelected = "ITEM SELECTED FROM THE LISTVIEW ARE ...\n\n" 
      for int k=0; k < listView1.SelectedIndices.Count ; k++)
      {
        StrSelected = StrSelected + "[" (k+1"]  " 
        // Get the item ( as ListViewItem ) at the selected index. 
        ListViewItem lvi = listView1.Items[listView1.SelectedIndices[k]];
        for int i=0; i < lvi.SubItems.Count ; i++)
        {
          // Get the subItem for the the selected item
          StrSelected = StrSelected + lvi.SubItems[i].Text + "\t";
        }
        StrSelected = StrSelected + "\n";
      }
      MessageBox.Show(StrSelected , "Selected Items");
    }

    private void CHECKED_Click(object sender, System.EventArgs e)
    {
      // Get the list of indices for all checked items
      string StrSelected = "ITEM CHECKED FROM THE LISTVIEW ARE ...\n\n" 
      for int k=0; k < listView1.CheckedIndices.Count; k++)
      {
        StrSelected = StrSelected + "[" (k+1"]  " 
        // Get the item ( as ListViewItem ) at the selected index. 
        ListViewItem lvi = listView1.Items[listView1.CheckedIndices[k]];
        for int i=0; i < lvi.SubItems.Count ; i++)
        {
          // Get the subItem for the the selected item
          StrSelected = StrSelected + lvi.SubItems[i].Text + "\t";
        }
        StrSelected = StrSelected + "\n";
      }
      MessageBox.Show(StrSelected , "Checked Items");
    }

      private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
      {
      
      }

      private void listView1_ColumnClick(object sender, System.Windows.Forms.ColumnClickEventArgs e)
      {
         if (listView1.Sorting == SortOrder.Descending)
            listView1.Sorting = SortOrder.Ascending;
         else
            listView1.Sorting = SortOrder.Descending;
         listView1.Sort();
      }


  }
}

           
       
ListView.zip( 46 k)
Related examples in the same category
1. ListView Item clicked eventListView Item clicked event
2. Folder Browser based on ListViewFolder Browser based on ListView
3. Sort a List View by Any ColumnSort a List View by Any Column
4. Add Data to a ListView
5. Extends ListViewItem
6. Use RadioButton to control the ListView display styleUse RadioButton to control the ListView display style
7. Display Directory info in a ListViewDisplay Directory info in a ListView
8. Add ListView column and insert ListView rowsAdd ListView column and insert ListView rows
9. ListView ExampleListView Example
10. Use ListView to display File info: name, size and dateUse ListView to display File info: name, size and date
11. Use ListView to display file name and double click the name to execute that fileUse ListView to display file name and double click the name to execute that file
12. Use ListView to diaplay folder info and double click to enter that directoryUse ListView to diaplay folder info and double click to enter that directory
www___.j_a_v___a__2_s___.__co___m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.