Extends ListViewItem : ListView « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » ListViewScreenshots 
Extends ListViewItem


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

public class Form1 : System.Windows.Forms.Form {
  private System.Windows.Forms.ListView lvCountries;
    private System.Windows.Forms.ImageList imgLarge;
    private System.Windows.Forms.ImageList imgSmall;
    private System.Windows.Forms.ComboBox cbView;
    private System.Windows.Forms.Label lblAbbreviation;
    private System.ComponentModel.IContainer components;

  public Form1() {
    InitializeComponent();
    lvCountries.Items.Add(new CountryItem("United States""US""Dollar"));
        lvCountries.Items[0].ImageIndex = 0;
        lvCountries.Items.Add(new CountryItem("Great Britain""GB""Pound"));
        lvCountries.Items[1].ImageIndex = 1;
        lvCountries.Items.Add(new CountryItem("Canada""CA""Dollar"));
        lvCountries.Items[2].ImageIndex = 2;
        lvCountries.Items.Add(new CountryItem("Japan""JP""Yen"));
        lvCountries.Items[3].ImageIndex = 3;
        lvCountries.Items.Add(new CountryItem("Germany""GM""Deutch Mark"));
        lvCountries.Items[4].ImageIndex = 4;

        cbView.Items.Add(View.LargeIcon);
        cbView.Items.Add(View.SmallIcon);
        cbView.Items.Add(View.List);
        cbView.Items.Add(View.Details);
        cbView.SelectedIndex = 0;

        lvCountries.Columns.Add("Country",100, HorizontalAlignment.Left);
        lvCountries.Columns.Add("Currency",100, HorizontalAlignment.Left);
    }
    private void InitializeComponent() {
      this.components = new System.ComponentModel.Container();
      this.lvCountries = new System.Windows.Forms.ListView();
      this.imgLarge = new System.Windows.Forms.ImageList(this.components);
      this.imgSmall = new System.Windows.Forms.ImageList(this.components);
      this.cbView = new System.Windows.Forms.ComboBox();
      this.lblAbbreviation = new System.Windows.Forms.Label();
      this.SuspendLayout();

      this.lvCountries.LargeImageList = this.imgLarge;
      this.lvCountries.Location = new System.Drawing.Point(2472);
      this.lvCountries.Name = "lvCountries";
      this.lvCountries.Size = new System.Drawing.Size(256248);
      this.lvCountries.SmallImageList = this.imgSmall;
      this.lvCountries.TabIndex = 0;
      this.lvCountries.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lvCountries_MouseUp);

      this.imgLarge.ImageSize = new System.Drawing.Size(4848);
      this.imgLarge.TransparentColor = System.Drawing.Color.Transparent;

      this.imgSmall.ColorDepth = System.Windows.Forms.ColorDepth.Depth16Bit;
      this.imgSmall.ImageSize = new System.Drawing.Size(1616);
      this.imgSmall.TransparentColor = System.Drawing.Color.Transparent;
      // 
      // cbView
      // 
      this.cbView.Location = new System.Drawing.Point(3232);
      this.cbView.Name = "cbView";
      this.cbView.Size = new System.Drawing.Size(12821);
      this.cbView.TabIndex = 1;
      this.cbView.SelectedIndexChanged += new System.EventHandler(this.cbView_SelectedIndexChanged);
      // 
      // lblAbbreviation
      // 
      this.lblAbbreviation.Location = new System.Drawing.Point(17632);
      this.lblAbbreviation.Name = "lblAbbreviation";
      this.lblAbbreviation.Size = new System.Drawing.Size(4823);
      this.lblAbbreviation.TabIndex = 2;
      // 
      // Form1
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(312339);
      this.Controls.Add(this.lblAbbreviation);
      this.Controls.Add(this.cbView);
      this.Controls.Add(this.lvCountries);
      this.Name = "Form1";
      this.Text = "Form1";
      this.ResumeLayout(false);

    }
    static void Main() {
    Application.Run(new Form1());
  }

    private void cbView_SelectedIndexChanged(object sender, System.EventArgs e)
    {
      lvCountries.View = (View)cbView.SelectedItem;
    }

    private void lvCountries_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
      if(lvCountries.View != View.Details)
        lblAbbreviation.Text = ((CountryItem)lvCountries.GetItemAt(e.X, e.Y)).CountryAbbreviation;
      else
        lblAbbreviation.Text = ((CountryItem)lvCountries.GetItemAt(5, e.Y)).CountryAbbreviation;
    }

    
  }
  public class CountryItem : System.Windows.Forms.ListViewItem {
    string countryName = "";
    string countryAbbrev = "";

    public CountryItem(string countryName, string countryAbbreviation, string currency)
    {
      countryName = countryName;
      countryAbbrev = countryAbbreviation;
            base.Text = countryName;
            base.SubItems.Add(currency);
    }

    public string CountryName
    {
      get  {return countryName;}
    }

    public string CountryAbbreviation
    {
      get  {return countryAbbrev;}
    }
  }


           
       
Related examples in the same category
1.Windows Explorer-Like Program: extends ListView
2.Dragging and dropping between ListView
3.ListView Item clicked eventListView Item clicked event
4.Folder Browser based on ListViewFolder Browser based on ListView
5.Set ColumnHeader for ListView
6.Sort a List View by Any ColumnSort a List View by Any Column
7.Add Data to a ListView
8.Use RadioButton to control the ListView display styleUse RadioButton to control the ListView display style
9.Display Directory info in a ListViewDisplay Directory info in a ListView
10.Add ListView column and insert ListView rowsAdd ListView column and insert ListView rows
11.Use ListViewItem to display file information
12.ListView ExampleListView Example
13.ListView Country: image and fontListView Country: image and font
14.Use ListView to display File info: name, size and dateUse ListView to display File info: name, size and date
15.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
16.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.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.