Use RadioButton to control the ListView display style : 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 
Use RadioButton to control the ListView display style
Use RadioButton to control the ListView display style

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

namespace ListView
{
  public class Form1 : System.Windows.Forms.Form
  {
    private System.Windows.Forms.RadioButton rdoLarge;
    private System.Windows.Forms.RadioButton rdoSmall;
    private System.Windows.Forms.RadioButton rdoList;
    private System.Windows.Forms.RadioButton rdoDetails;
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.ImageList ilLarge;
    private System.Windows.Forms.ImageList ilSmall;
    private System.Windows.Forms.ListView lwFilesAndFolders;
    private System.Windows.Forms.Label lblCurrentPath;

    public Form1()
    {
      InitializeComponent();
      CreateHeadersAndFillListView();
      PaintListView();
    }

    private void InitializeComponent()
    {
//      System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
      this.groupBox1 = new System.Windows.Forms.GroupBox();
      this.rdoDetails = new System.Windows.Forms.RadioButton();
      this.rdoList = new System.Windows.Forms.RadioButton();
      this.rdoSmall = new System.Windows.Forms.RadioButton();
      this.rdoLarge = new System.Windows.Forms.RadioButton();
      this.lblCurrentPath = new System.Windows.Forms.Label();
      this.ilLarge = new System.Windows.Forms.ImageList();
      this.ilSmall = new System.Windows.Forms.ImageList();
      this.lwFilesAndFolders = new System.Windows.Forms.ListView();
      this.groupBox1.SuspendLayout();
      this.SuspendLayout();

      this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {this.rdoDetails,
                                                                            this.rdoList,
                                                                            this.rdoSmall,
                                                                            this.rdoLarge});
      this.groupBox1.Location = new System.Drawing.Point(42432);
      this.groupBox1.Name = "groupBox1";
      this.groupBox1.Size = new System.Drawing.Size(120128);
      this.groupBox1.TabIndex = 2;
      this.groupBox1.TabStop = false;
      this.groupBox1.Text = "View mode";
      // 
      // rdoDetails
      // 
      this.rdoDetails.Checked = true;
      this.rdoDetails.Location = new System.Drawing.Point(896);
      this.rdoDetails.Name = "rdoDetails";
      this.rdoDetails.Size = new System.Drawing.Size(10416);
      this.rdoDetails.TabIndex = 3;
      this.rdoDetails.TabStop = true;
      this.rdoDetails.Text = "Details";
      this.rdoDetails.CheckedChanged += new System.EventHandler(this.rdoDetails_CheckedChanged);
      // 
      // rdoList
      // 
      this.rdoList.Location = new System.Drawing.Point(872);
      this.rdoList.Name = "rdoList";
      this.rdoList.Size = new System.Drawing.Size(10416);
      this.rdoList.TabIndex = 2;
      this.rdoList.Text = "List";
      this.rdoList.CheckedChanged += new System.EventHandler(this.rdoList_CheckedChanged);
      // 
      // rdoSmall
      // 
      this.rdoSmall.Location = new System.Drawing.Point(848);
      this.rdoSmall.Name = "rdoSmall";
      this.rdoSmall.Size = new System.Drawing.Size(10416);
      this.rdoSmall.TabIndex = 1;
      this.rdoSmall.Text = "SmallIcon";
      this.rdoSmall.CheckedChanged += new System.EventHandler(this.rdoSmall_CheckedChanged);
      // 
      // rdoLarge
      // 
      this.rdoLarge.Location = new System.Drawing.Point(824);
      this.rdoLarge.Name = "rdoLarge";
      this.rdoLarge.Size = new System.Drawing.Size(9616);
      this.rdoLarge.TabIndex = 0;
      this.rdoLarge.Text = "LargeIcon";
      this.rdoLarge.CheckedChanged += new System.EventHandler(this.rdoLarge_CheckedChanged);
      // 
      // ilLarge
      // 
      this.ilLarge.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
      this.ilLarge.ImageSize = new System.Drawing.Size(3232);
//      this.ilLarge.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilLarge.ImageStream")));
      this.ilLarge.TransparentColor = System.Drawing.Color.Transparent;
      // 
      // ilSmall
      // 
      this.ilSmall.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
      this.ilSmall.ImageSize = new System.Drawing.Size(1616);
//      this.ilSmall.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("ilSmall.ImageStream")));
      this.ilSmall.TransparentColor = System.Drawing.Color.Transparent;
      // 
      // lwFilesAndFolders
      // 
      this.lwFilesAndFolders.LargeImageList = this.ilLarge;
      this.lwFilesAndFolders.Location = new System.Drawing.Point(1632);
      this.lwFilesAndFolders.MultiSelect = false;
      this.lwFilesAndFolders.Name = "lwFilesAndFolders";
      this.lwFilesAndFolders.Size = new System.Drawing.Size(400216);
      this.lwFilesAndFolders.SmallImageList = this.ilSmall;
      this.lwFilesAndFolders.TabIndex = 0;
      this.lwFilesAndFolders.View = System.Windows.Forms.View.List;
      // 
      // Form1
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(552293);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {this.groupBox1, this.lwFilesAndFolders});
      this.Name = "Form1";
      this.Text = "ListView";
      this.groupBox1.ResumeLayout(false);
      this.ResumeLayout(false);
    }
    static void Main() 
    {
      Application.Run(new Form1());
    }

    private void CreateHeadersAndFillListView()
    {
      ColumnHeader colHead;

      colHead = new ColumnHeader();
      colHead.Text = "Filename";
      this.lwFilesAndFolders.Columns.Add(colHead)
      
      colHead = new ColumnHeader();
      colHead.Text = "Size";
      this.lwFilesAndFolders.Columns.Add(colHead);
      
      colHead = new ColumnHeader();
      colHead.Text = "Last accessed";
      this.lwFilesAndFolders.Columns.Add(colHead)
    }

    private void PaintListView()
    {
      ListViewItem lvi;
      ListViewItem.ListViewSubItem lvsi;

      this.lwFilesAndFolders.Items.Clear();
      this.lwFilesAndFolders.BeginUpdate();

      lvi = new ListViewItem();
      lvi.Text = "A"
      lvi.ImageIndex = 0
      lvi.Tag = "tag";

      lvsi = new ListViewItem.ListViewSubItem();
      lvsi.Text = "4"
      lvi.SubItems.Add(lvsi)
          
      lvsi = new ListViewItem.ListViewSubItem();
      lvsi.Text = "C"
      lvi.SubItems.Add(lvsi)
      this.lwFilesAndFolders.Items.Add(lvi);

      this.lwFilesAndFolders.EndUpdate();
      this.lwFilesAndFolders.View = View.Details;
    }

    private void rdoLarge_CheckedChanged(object sender, System.EventArgs e)
    {
      RadioButton rdb = (RadioButton)sender;
      if (rdb.Checked)
        this.lwFilesAndFolders.View = View.LargeIcon;
    }

    private void rdoList_CheckedChanged(object sender, System.EventArgs e)
    {
      RadioButton rdb = (RadioButton)sender;
      if (rdb.Checked)
        this.lwFilesAndFolders.View = View.List;
    }

    private void rdoSmall_CheckedChanged(object sender, System.EventArgs e)
    {
      RadioButton rdb = (RadioButton)sender;
      if (rdb.Checked)
        this.lwFilesAndFolders.View = View.SmallIcon;
    }

    private void rdoDetails_CheckedChanged(object sender, System.EventArgs e)
    {
      RadioButton rdb = (RadioButton)sender;
      if (rdb.Checked)
        this.lwFilesAndFolders.View = View.Details;
    }
  }
}


           
       
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.Extends ListViewItem
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.