By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,572 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,572 IT Pros & Developers. It's quick & easy.

item text in the ListView control overlaps other items in small icon view

P: 28
In my application ListView is inside panel (XP theme enable), item text in the ListView control overlaps other items in small icon view. The items are drawn as if aligned to a grid and this causes items to be drawn in overlapped manner which obviosuly looks horrrible. I have tried to change allignment with no success. There is no problem regarding List and Details mode.

What might be the problem?
Feb 2 '09 #1
Share this Question
Share on Google+
1 Reply


P: 28
Code is attached.
Note that when I press 'F5' in SmallIcon view mode. There is very frustating problem. How can I get rid of this problem?

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7.  
  8. namespace Others.ListViewSmallIcon
  9. {
  10.     /// <summary>
  11.     /// Summary description for ListViewCountry.
  12.     /// </summary>
  13.     public class ListViewCountry : System.Windows.Forms.Form
  14.     {
  15.         private ListViewEx listView1;
  16.         private System.Windows.Forms.ColumnHeader Country;
  17.         private System.Windows.Forms.ColumnHeader Capital;
  18.         private System.Windows.Forms.ColumnHeader City_1;
  19.         private System.Windows.Forms.ColumnHeader City_2;
  20.         private System.Windows.Forms.Button REPORT;
  21.         private System.Windows.Forms.Button LIST;
  22.         private System.Windows.Forms.Button SMALLICON;
  23.         private System.Windows.Forms.Button LARGEICON;
  24.         ImageList ig = new ImageList();
  25.         private System.Windows.Forms.Button SELECTED;
  26.         private System.Windows.Forms.Button CHECKED;
  27.         private System.Windows.Forms.Panel panel1;
  28.         /// <summary>
  29.         /// Required designer variable.
  30.         /// </summary>
  31.         private System.ComponentModel.Container components = null;
  32.  
  33.         public ListViewCountry()
  34.         {
  35.             //
  36.             // Required for Windows Form Designer support
  37.             //
  38.             InitializeComponent();
  39.             //Application.EnableVisualStyles();
  40.             //Application.
  41.  
  42.             //
  43.             // TODO: Add any constructor code after InitializeComponent call
  44.             //
  45.         }
  46.  
  47.         /// <summary>
  48.         /// Clean up any resources being used.
  49.         /// </summary>
  50.         protected override void Dispose(bool disposing)
  51.         {
  52.             if (disposing)
  53.             {
  54.                 if (components != null)
  55.                 {
  56.                     components.Dispose();
  57.                 }
  58.             }
  59.             base.Dispose(disposing);
  60.         }
  61.  
  62.         #region Windows Form Designer generated code
  63.         /// <summary>
  64.         /// Required method for Designer support - do not modify
  65.         /// the contents of this method with the code editor.
  66.         /// </summary>
  67.         private void InitializeComponent()
  68.         {
  69.             this.listView1 = new Others.ListViewSmallIcon.ListViewEx();
  70.             this.Country = new System.Windows.Forms.ColumnHeader();
  71.             this.Capital = new System.Windows.Forms.ColumnHeader();
  72.             this.City_1 = new System.Windows.Forms.ColumnHeader();
  73.             this.City_2 = new System.Windows.Forms.ColumnHeader();
  74.             this.REPORT = new System.Windows.Forms.Button();
  75.             this.LIST = new System.Windows.Forms.Button();
  76.             this.SMALLICON = new System.Windows.Forms.Button();
  77.             this.LARGEICON = new System.Windows.Forms.Button();
  78.             this.SELECTED = new System.Windows.Forms.Button();
  79.             this.CHECKED = new System.Windows.Forms.Button();
  80.             this.panel1 = new System.Windows.Forms.Panel();
  81.             this.panel1.SuspendLayout();
  82.             this.SuspendLayout();
  83.             // 
  84.             // listView1
  85.             // 
  86.             this.listView1.AllowColumnReorder = true;
  87.             this.listView1.CheckBoxes = true;
  88.             this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
  89.             this.Country,
  90.             this.Capital,
  91.             this.City_1,
  92.             this.City_2});
  93.             this.listView1.Dock = System.Windows.Forms.DockStyle.Top;
  94.             this.listView1.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  95.             this.listView1.ForeColor = System.Drawing.SystemColors.HotTrack;
  96.             this.listView1.Location = new System.Drawing.Point(0, 0);
  97.             this.listView1.Name = "listView1";
  98.             this.listView1.ShowControlOnlyWhenSelected = false;
  99.             this.listView1.Size = new System.Drawing.Size(464, 152);
  100.             this.listView1.TabIndex = 0;
  101.             this.listView1.UseCompatibleStateImageBehavior = false;
  102.             this.listView1.View = System.Windows.Forms.View.Details;
  103.             this.listView1.WordWarpMaxWidth = 15;
  104.             this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
  105.             this.listView1.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.listView1_ColumnClick);
  106.             this.listView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.listView1_KeyDown);
  107.             // 
  108.             // Country
  109.             // 
  110.             this.Country.Text = "Country";
  111.             this.Country.Width = 100;
  112.             // 
  113.             // Capital
  114.             // 
  115.             this.Capital.Text = "Capital";
  116.             this.Capital.Width = 150;
  117.             // 
  118.             // City_1
  119.             // 
  120.             this.City_1.Text = "City_1";
  121.             this.City_1.Width = 100;
  122.             // 
  123.             // City_2
  124.             // 
  125.             this.City_2.Text = "City_2";
  126.             this.City_2.Width = 100;
  127.             // 
  128.             // REPORT
  129.             // 
  130.             this.REPORT.Dock = System.Windows.Forms.DockStyle.Left;
  131.             this.REPORT.Location = new System.Drawing.Point(75, 0);
  132.             this.REPORT.Name = "REPORT";
  133.             this.REPORT.Size = new System.Drawing.Size(75, 24);
  134.             this.REPORT.TabIndex = 1;
  135.             this.REPORT.Text = "Report";
  136.             this.REPORT.Click += new System.EventHandler(this.REPORT_Click);
  137.             // 
  138.             // LIST
  139.             // 
  140.             this.LIST.Dock = System.Windows.Forms.DockStyle.Left;
  141.             this.LIST.Location = new System.Drawing.Point(300, 0);
  142.             this.LIST.Name = "LIST";
  143.             this.LIST.Size = new System.Drawing.Size(75, 24);
  144.             this.LIST.TabIndex = 1;
  145.             this.LIST.Text = "List";
  146.             this.LIST.Click += new System.EventHandler(this.LIST_Click);
  147.             // 
  148.             // SMALLICON
  149.             // 
  150.             this.SMALLICON.Dock = System.Windows.Forms.DockStyle.Left;
  151.             this.SMALLICON.Location = new System.Drawing.Point(150, 0);
  152.             this.SMALLICON.Name = "SMALLICON";
  153.             this.SMALLICON.Size = new System.Drawing.Size(75, 24);
  154.             this.SMALLICON.TabIndex = 1;
  155.             this.SMALLICON.Text = "Small Icon";
  156.             this.SMALLICON.Click += new System.EventHandler(this.SMALLICON_Click);
  157.             // 
  158.             // LARGEICON
  159.             // 
  160.             this.LARGEICON.Dock = System.Windows.Forms.DockStyle.Left;
  161.             this.LARGEICON.Location = new System.Drawing.Point(375, 0);
  162.             this.LARGEICON.Name = "LARGEICON";
  163.             this.LARGEICON.Size = new System.Drawing.Size(75, 24);
  164.             this.LARGEICON.TabIndex = 1;
  165.             this.LARGEICON.Text = "Large Icon";
  166.             this.LARGEICON.Click += new System.EventHandler(this.LARGEICON_Click);
  167.             // 
  168.             // SELECTED
  169.             // 
  170.             this.SELECTED.Dock = System.Windows.Forms.DockStyle.Left;
  171.             this.SELECTED.Location = new System.Drawing.Point(0, 0);
  172.             this.SELECTED.Name = "SELECTED";
  173.             this.SELECTED.Size = new System.Drawing.Size(75, 24);
  174.             this.SELECTED.TabIndex = 2;
  175.             this.SELECTED.Text = "Selected";
  176.             this.SELECTED.Click += new System.EventHandler(this.SELECTED_Click);
  177.             // 
  178.             // CHECKED
  179.             // 
  180.             this.CHECKED.Dock = System.Windows.Forms.DockStyle.Left;
  181.             this.CHECKED.Location = new System.Drawing.Point(225, 0);
  182.             this.CHECKED.Name = "CHECKED";
  183.             this.CHECKED.Size = new System.Drawing.Size(75, 24);
  184.             this.CHECKED.TabIndex = 3;
  185.             this.CHECKED.Text = "Checked";
  186.             this.CHECKED.Click += new System.EventHandler(this.CHECKED_Click);
  187.             // 
  188.             // panel1
  189.             // 
  190.             this.panel1.Controls.Add(this.LARGEICON);
  191.             this.panel1.Controls.Add(this.LIST);
  192.             this.panel1.Controls.Add(this.CHECKED);
  193.             this.panel1.Controls.Add(this.SMALLICON);
  194.             this.panel1.Controls.Add(this.REPORT);
  195.             this.panel1.Controls.Add(this.SELECTED);
  196.             this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
  197.             this.panel1.Location = new System.Drawing.Point(0, 157);
  198.             this.panel1.Name = "panel1";
  199.             this.panel1.Size = new System.Drawing.Size(464, 24);
  200.             this.panel1.TabIndex = 4;
  201.             // 
  202.             // ListViewCountry
  203.             // 
  204.             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  205.             this.ClientSize = new System.Drawing.Size(464, 181);
  206.             this.Controls.Add(this.panel1);
  207.             this.Controls.Add(this.listView1);
  208.             this.Name = "ListViewCountry";
  209.             this.Text = "ListView";
  210.             this.Load += new System.EventHandler(this.ListViewCountry_Load);
  211.             this.panel1.ResumeLayout(false);
  212.             this.ResumeLayout(false);
  213.  
  214.         }
  215.         #endregion
  216.  
  217.         private void ListViewCountry_Load(object sender, System.EventArgs e)
  218.         {
  219.             // Create an image list of icons that you want to display for each item
  220.             ig.Images.Add(new Bitmap("C:\\FS\\Long File name of file is this (22).jpg"));
  221.             ig.Images.Add(new Bitmap("C:\\FS\\Long File name of file is this (22).jpg"));
  222.             ig.Images.Add(new Bitmap("C:\\FS\\Long File name of file is this (22).jpg"));
  223.             ig.Images.Add(new Bitmap("C:\\FS\\Long File name of file is this (22).jpg"));
  224.             ig.Images.Add(new Bitmap("C:\\FS\\Long File name of file is this (22).jpg"));
  225.  
  226.             // Set the Imagelist for SmallIcons
  227.             listView1.SmallImageList = ig;
  228.             // Set the ImageList for LargeIcons 
  229.             listView1.LargeImageList = ig;
  230.  
  231.             // Align the columns 1,2,3 and the column data as Center
  232.             listView1.Columns[1].TextAlign = HorizontalAlignment.Center;
  233.             listView1.Columns[2].TextAlign = HorizontalAlignment.Center;
  234.             listView1.Columns[3].TextAlign = HorizontalAlignment.Center;
  235.  
  236.             // Create a ListViewItem object for evey item that you wish to add the ListView.
  237.             string[] lv = new String[4];
  238.             lv[0] = "USA";
  239.             lv[1] = "Washington DC";
  240.             lv[2] = "New York";
  241.             lv[3] = "Los Angeles";
  242.             listView1.Items.Add(new ListViewItem(lv, 0));
  243.  
  244.             lv[0] = "Italy";
  245.             lv[1] = "Rome";
  246.             lv[2] = "Venice";
  247.             lv[3] = "Milan";
  248.             listView1.Items.Add(new ListViewItem(lv, 1));
  249.  
  250.             lv[0] = "Canada";
  251.             lv[1] = "Ottawa";
  252.             lv[2] = "Montreal";
  253.             lv[3] = "Quebec";
  254.             listView1.Items.Add(new ListViewItem(lv, 2));
  255.  
  256.             lv[0] = "Switzerland";
  257.             lv[1] = "Geneva";
  258.             lv[2] = "Zurich";
  259.             lv[3] = "Lucerne";
  260.             listView1.Items.Add(new ListViewItem(lv, 3));
  261.  
  262.             lv[0] = "UnitedKingdom";
  263.             lv[1] = "London";
  264.             lv[2] = "ChesterField";
  265.             lv[3] = "Wembly";
  266.             listView1.Items.Add(new ListViewItem(lv, 4));
  267.  
  268.             lv[0] = "Republic of Nepal";
  269.             lv[1] = "Kathmandu";
  270.             lv[2] = "Pokhara";
  271.             lv[3] = "Khadichaur";
  272.             listView1.Items.Add(new ListViewItem(lv, 1));
  273.             lv = new String[4];
  274.             lv[0] = "USA";
  275.             lv[1] = "Washington DC";
  276.             lv[2] = "New York";
  277.             lv[3] = "Los Angeles";
  278.             listView1.Items.Add(new ListViewItem(lv, 0));
  279.  
  280.             lv[0] = "Italy";
  281.             lv[1] = "Rome";
  282.             lv[2] = "Venice";
  283.             lv[3] = "Milan";
  284.             listView1.Items.Add(new ListViewItem(lv, 1));
  285.  
  286.             lv[0] = "Canada";
  287.             lv[1] = "Ottawa";
  288.             lv[2] = "Montreal";
  289.             lv[3] = "Quebec";
  290.             listView1.Items.Add(new ListViewItem(lv, 2));
  291.  
  292.             lv[0] = "Switzerland";
  293.             lv[1] = "Geneva";
  294.             lv[2] = "Zurich";
  295.             lv[3] = "Lucerne";
  296.             listView1.Items.Add(new ListViewItem(lv, 3));
  297.  
  298.             lv[0] = "UnitedKingdom";
  299.             lv[1] = "London";
  300.             lv[2] = "ChesterField";
  301.             lv[3] = "Wembly";
  302.             listView1.Items.Add(new ListViewItem(lv, 4));
  303.  
  304.             lv[0] = "Republic of Nepal";
  305.             lv[1] = "Kathmandu";
  306.             lv[2] = "Pokhara";
  307.             lv[3] = "Khadichaur";
  308.             listView1.Items.Add(new ListViewItem(lv, 1));
  309.            lv = new String[4];
  310.             lv[0] = "USA";
  311.             lv[1] = "Washington DC";
  312.             lv[2] = "New York";
  313.             lv[3] = "Los Angeles";
  314.             listView1.Items.Add(new ListViewItem(lv, 0));
  315.  
  316.             lv[0] = "Italy";
  317.             lv[1] = "Rome";
  318.             lv[2] = "Venice";
  319.             lv[3] = "Milan";
  320.             listView1.Items.Add(new ListViewItem(lv, 1));
  321.  
  322.             lv[0] = "Canada";
  323.             lv[1] = "Ottawa";
  324.             lv[2] = "Montreal";
  325.             lv[3] = "Quebec";
  326.             listView1.Items.Add(new ListViewItem(lv, 2));
  327.  
  328.             lv[0] = "Switzerland";
  329.             lv[1] = "Geneva";
  330.             lv[2] = "Zurich";
  331.             lv[3] = "Lucerne";
  332.             listView1.Items.Add(new ListViewItem(lv, 3));
  333.  
  334.             lv[0] = "UnitedKingdom";
  335.             lv[1] = "London";
  336.             lv[2] = "ChesterField";
  337.             lv[3] = "Wembly";
  338.             listView1.Items.Add(new ListViewItem(lv, 4));
  339.  
  340.             lv[0] = "Republic of Nepal";
  341.             lv[1] = "Kathmandu";
  342.             lv[2] = "Pokhara";
  343.             lv[3] = "Khadichaur";
  344.             listView1.Items.Add(new ListViewItem(lv, 1));
  345.             lv = new String[4];
  346.             lv[0] = "USA";
  347.             lv[1] = "Washington DC";
  348.             lv[2] = "New York";
  349.             lv[3] = "Los Angeles";
  350.             listView1.Items.Add(new ListViewItem(lv, 0));
  351.  
  352.             lv[0] = "Italy";
  353.             lv[1] = "Rome";
  354.             lv[2] = "Venice";
  355.             lv[3] = "Milan";
  356.             listView1.Items.Add(new ListViewItem(lv, 1));
  357.  
  358.             lv[0] = "Canada";
  359.             lv[1] = "Ottawa";
  360.             lv[2] = "Montreal";
  361.             lv[3] = "Quebec";
  362.             listView1.Items.Add(new ListViewItem(lv, 2));
  363.  
  364.             lv[0] = "Switzerland";
  365.             lv[1] = "Geneva";
  366.             lv[2] = "Zurich";
  367.             lv[3] = "Lucerne";
  368.             listView1.Items.Add(new ListViewItem(lv, 3));
  369.  
  370.             lv[0] = "UnitedKingdom";
  371.             lv[1] = "London";
  372.             lv[2] = "ChesterField";
  373.             lv[3] = "Wembly";
  374.             listView1.Items.Add(new ListViewItem(lv, 4));
  375.  
  376.             lv[0] = "Republic of Nepal";
  377.             lv[1] = "Kathmandu";
  378.             lv[2] = "Pokhara";
  379.             lv[3] = "Khadichaur";
  380.             listView1.Items.Add(new ListViewItem(lv, 1));
  381.             lv = new String[4];
  382.             lv[0] = "USA";
  383.             lv[1] = "Washington DC";
  384.             lv[2] = "New York";
  385.             lv[3] = "Los Angeles";
  386.             listView1.Items.Add(new ListViewItem(lv, 0));
  387.  
  388.             lv[0] = "Italy";
  389.             lv[1] = "Rome";
  390.             lv[2] = "Venice";
  391.             lv[3] = "Milan";
  392.             listView1.Items.Add(new ListViewItem(lv, 1));
  393.  
  394.             lv[0] = "Canada";
  395.             lv[1] = "Ottawa";
  396.             lv[2] = "Montreal";
  397.             lv[3] = "Quebec";
  398.             listView1.Items.Add(new ListViewItem(lv, 2));
  399.  
  400.             lv[0] = "Switzerland";
  401.             lv[1] = "Geneva";
  402.             lv[2] = "Zurich";
  403.             lv[3] = "Lucerne";
  404.             listView1.Items.Add(new ListViewItem(lv, 3));
  405.  
  406.             lv[0] = "UnitedKingdom";
  407.             lv[1] = "London";
  408.             lv[2] = "ChesterField";
  409.             lv[3] = "Wembly";
  410.             listView1.Items.Add(new ListViewItem(lv, 4));
  411.  
  412.             lv[0] = "Republic of Nepal";
  413.             lv[1] = "Kathmandu";
  414.             lv[2] = "Pokhara";
  415.             lv[3] = "Khadichaur";
  416.             listView1.Items.Add(new ListViewItem(lv, 1));
  417.             lv = new String[4];
  418.             lv[0] = "USA";
  419.             lv[1] = "Washington DC";
  420.             lv[2] = "New York";
  421.             lv[3] = "Los Angeles";
  422.             listView1.Items.Add(new ListViewItem(lv, 0));
  423.  
  424.             lv[0] = "Italy";
  425.             lv[1] = "Rome";
  426.             lv[2] = "Venice";
  427.             lv[3] = "Milan";
  428.             listView1.Items.Add(new ListViewItem(lv, 1));
  429.  
  430.             lv[0] = "Canada";
  431.             lv[1] = "Ottawa";
  432.             lv[2] = "Montreal";
  433.             lv[3] = "Quebec";
  434.             listView1.Items.Add(new ListViewItem(lv, 2));
  435.  
  436.             lv[0] = "Switzerland";
  437.             lv[1] = "Geneva";
  438.             lv[2] = "Zurich";
  439.             lv[3] = "Lucerne";
  440.             listView1.Items.Add(new ListViewItem(lv, 3));
  441.  
  442.             lv[0] = "UnitedKingdom";
  443.             lv[1] = "London";
  444.             lv[2] = "ChesterField";
  445.             lv[3] = "Wembly";
  446.             listView1.Items.Add(new ListViewItem(lv, 4));
  447.  
  448.             lv[0] = "Republic of Nepal";
  449.             lv[1] = "Kathmandu";
  450.             lv[2] = "Pokhara";
  451.             lv[3] = "Khadichaur";
  452.             listView1.Items.Add(new ListViewItem(lv, 1));
  453.             lv = new String[4];
  454.             lv[0] = "USA";
  455.             lv[1] = "Washington DC";
  456.             lv[2] = "New York";
  457.             lv[3] = "Los Angeles";
  458.             listView1.Items.Add(new ListViewItem(lv, 0));
  459.  
  460.             lv[0] = "Italy";
  461.             lv[1] = "Rome";
  462.             lv[2] = "Venice";
  463.             lv[3] = "Milan";
  464.             listView1.Items.Add(new ListViewItem(lv, 1));
  465.  
  466.             lv[0] = "Canada";
  467.             lv[1] = "Ottawa";
  468.             lv[2] = "Montreal";
  469.             lv[3] = "Quebec";
  470.             listView1.Items.Add(new ListViewItem(lv, 2));
  471.  
  472.             lv[0] = "Switzerland";
  473.             lv[1] = "Geneva";
  474.             lv[2] = "Zurich";
  475.             lv[3] = "Lucerne";
  476.             listView1.Items.Add(new ListViewItem(lv, 3));
  477.  
  478.             lv[0] = "UnitedKingdom";
  479.             lv[1] = "London";
  480.             lv[2] = "ChesterField";
  481.             lv[3] = "Wembly";
  482.             listView1.Items.Add(new ListViewItem(lv, 4));
  483.  
  484.             lv[0] = "Republic of Nepal";
  485.             lv[1] = "Kathmandu";
  486.             lv[2] = "Pokhara";
  487.             lv[3] = "Khadichaur";
  488.             listView1.Items.Add(new ListViewItem(lv, 1));
  489.             lv = new String[4];
  490.             lv[0] = "USA";
  491.             lv[1] = "Washington DC";
  492.             lv[2] = "New York";
  493.             lv[3] = "Los Angeles";
  494.             listView1.Items.Add(new ListViewItem(lv, 0));
  495.  
  496.             lv[0] = "Italy";
  497.             lv[1] = "Rome";
  498.             lv[2] = "Venice";
  499.             lv[3] = "Milan";
  500.             listView1.Items.Add(new ListViewItem(lv, 1));
  501.  
  502.             lv[0] = "Canada";
  503.             lv[1] = "Ottawa";
  504.             lv[2] = "Montreal";
  505.             lv[3] = "Quebec";
  506.             listView1.Items.Add(new ListViewItem(lv, 2));
  507.  
  508.             lv[0] = "Switzerland";
  509.             lv[1] = "Geneva";
  510.             lv[2] = "Zurich";
  511.             lv[3] = "Lucerne";
  512.             listView1.Items.Add(new ListViewItem(lv, 3));
  513.  
  514.             lv[0] = "UnitedKingdom";
  515.             lv[1] = "London";
  516.             lv[2] = "ChesterField";
  517.             lv[3] = "Wembly";
  518.             listView1.Items.Add(new ListViewItem(lv, 4));
  519.  
  520.             lv[0] = "Republic of Nepal";
  521.             lv[1] = "Kathmandu";
  522.             lv[2] = "Pokhara";
  523.             lv[3] = "Khadichaur";
  524.             listView1.Items.Add(new ListViewItem(lv, 1));
  525.  
  526.             for (int j = 0; j < listView1.Items.Count; j++)
  527.             {
  528.                 ListViewItem lvi = listView1.Items[j];
  529.                 for (int i = 0; i < lvi.SubItems.Count; i++)
  530.                 {
  531.                     Console.Write(lvi.SubItems[i].Text + "\t");
  532.                 }
  533.                 Console.WriteLine("\n");
  534.             }
  535.         }
  536.  
  537.         private void REPORT_Click(object sender, System.EventArgs e)
  538.         {
  539.             // Switch to the Report View
  540.             this.Text = "Report View";
  541.             listView1.View = View.Details;
  542.         }
  543.  
  544.         private void LARGEICON_Click(object sender, System.EventArgs e)
  545.         {
  546.             // Switch to the LargeIcon view
  547.             this.Text = "LargeIcon View";
  548.             listView1.View = View.LargeIcon;
  549.         }
  550.  
  551.         private void SMALLICON_Click(object sender, System.EventArgs e)
  552.         {
  553.             // Switch to the SmallIcon view
  554.             this.Text = "SmallIcon View";
  555.             listView1.View = View.SmallIcon;
  556.         }
  557.  
  558.         private void LIST_Click(object sender, System.EventArgs e)
  559.         {
  560.             // Switch to the List view
  561.             this.Text = "List View";
  562.             listView1.View = View.List;
  563.         }
  564.  
  565.         private void SELECTED_Click(object sender, System.EventArgs e)
  566.         {
  567.             // Get the list of indices for all the selected items
  568.  
  569.             string StrSelected = "ITEM SELECTED FROM THE LISTVIEW ARE ...\n\n";
  570.             for (int k = 0; k < listView1.SelectedIndices.Count; k++)
  571.             {
  572.                 StrSelected = StrSelected + "[" + (k + 1) + "]  ";
  573.                 // Get the item ( as ListViewItem ) at the selected index. 
  574.                 ListViewItem lvi = listView1.Items[listView1.SelectedIndices[k]];
  575.                 for (int i = 0; i < lvi.SubItems.Count; i++)
  576.                 {
  577.                     // Get the subItem for the the selected item
  578.                     StrSelected = StrSelected + lvi.SubItems[i].Text + "\t";
  579.                 }
  580.                 StrSelected = StrSelected + "\n";
  581.             }
  582.             MessageBox.Show(StrSelected, "Selected Items");
  583.         }
  584.  
  585.         private void CHECKED_Click(object sender, System.EventArgs e)
  586.         {
  587.             // Get the list of indices for all checked items
  588.             string StrSelected = "ITEM CHECKED FROM THE LISTVIEW ARE ...\n\n";
  589.             for (int k = 0; k < listView1.CheckedIndices.Count; k++)
  590.             {
  591.                 StrSelected = StrSelected + "[" + (k + 1) + "]  ";
  592.                 // Get the item ( as ListViewItem ) at the selected index. 
  593.                 ListViewItem lvi = listView1.Items[listView1.CheckedIndices[k]];
  594.                 for (int i = 0; i < lvi.SubItems.Count; i++)
  595.                 {
  596.                     // Get the subItem for the the selected item
  597.                     StrSelected = StrSelected + lvi.SubItems[i].Text + "\t";
  598.                 }
  599.                 StrSelected = StrSelected + "\n";
  600.             }
  601.             MessageBox.Show(StrSelected, "Checked Items");
  602.         }
  603.  
  604.         private void listView1_SelectedIndexChanged(object sender, System.EventArgs e)
  605.         {
  606.  
  607.         }
  608.  
  609.         private void listView1_ColumnClick(object sender, System.Windows.Forms.ColumnClickEventArgs e)
  610.         {
  611.             if (listView1.Sorting == SortOrder.Descending)
  612.                 listView1.Sorting = SortOrder.Ascending;
  613.             else
  614.                 listView1.Sorting = SortOrder.Descending;
  615.             listView1.Sort();
  616.         }
  617.  
  618.         private void listView1_KeyDown(object sender, KeyEventArgs e)
  619.         {
  620.             if (e.KeyCode == Keys.F5)
  621.             {
  622.                 listView1.Items.Clear();
  623.                 ListViewCountry_Load(null, null);
  624.                 listView1.AutoArrange = true;
  625.             }
  626.         }
  627.  
  628.     }
  629. }
Feb 2 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.