Csharp/C Sharp by API/System.Windows.Forms/ListView
Содержание
extends ListView
using System;
using System.Diagnostics; // For Process.Start
using System.Drawing;
using System.IO;
using System.Windows.Forms;
class FileListView : ListView {
string strDirectory;
public FileListView() {
View = View.Details;
ImageList imglst = new ImageList();
imglst.Images.Add(new Bitmap(GetType(), "DOC.BMP"));
imglst.Images.Add(new Bitmap(GetType(), "EXE.BMP"));
SmallImageList = imglst;
LargeImageList = imglst;
Columns.Add("Name", 100, HorizontalAlignment.Left);
Columns.Add("Size", 100, HorizontalAlignment.Right);
Columns.Add("Modified", 100, HorizontalAlignment.Left);
Columns.Add("Attribute", 100, HorizontalAlignment.Left);
}
public void ShowFiles(string strDirectory) {
this.strDirectory = strDirectory;
Items.Clear();
DirectoryInfo dirinfo = new DirectoryInfo(strDirectory);
FileInfo[] afileinfo;
try {
afileinfo = dirinfo.GetFiles();
} catch {
return;
}
foreach (FileInfo fi in afileinfo) {
ListViewItem lvi = new ListViewItem(fi.Name);
if (Path.GetExtension(fi.Name).ToUpper() == ".EXE")
lvi.ImageIndex = 1;
else
lvi.ImageIndex = 0;
lvi.SubItems.Add(fi.Length.ToString("N0"));
lvi.SubItems.Add(fi.LastWriteTime.ToString());
string strAttr = "";
if ((fi.Attributes & FileAttributes.Archive) != 0)
strAttr += "A";
if ((fi.Attributes & FileAttributes.Hidden) != 0)
strAttr += "H";
if ((fi.Attributes & FileAttributes.ReadOnly) != 0)
strAttr += "R";
if ((fi.Attributes & FileAttributes.System) != 0)
strAttr += "S";
lvi.SubItems.Add(strAttr);
Items.Add(lvi);
}
}
protected override void OnItemActivate(EventArgs ea) {
base.OnItemActivate(ea);
foreach (ListViewItem lvi in SelectedItems) {
try {
Process.Start(Path.rubine(strDirectory, lvi.Text));
} catch {
continue;
}
}
}
}
class ExplorerLike : Form {
FileListView filelist;
MenuItemView mivChecked;
public static void Main() {
Application.Run(new ExplorerLike());
}
public ExplorerLike() {
BackColor = SystemColors.Window;
ForeColor = SystemColors.WindowText;
filelist = new FileListView();
filelist.Parent = this;
filelist.Dock = DockStyle.Fill;
Splitter split = new Splitter();
split.Parent = this;
split.Dock = DockStyle.Left;
split.BackColor = SystemColors.Control;
Menu = new MainMenu();
Menu.MenuItems.Add("&View");
string[] astrView = { "Lar&ge Icons", "S&mall Icons",
"&List", "&Details" };
View[] aview = { View.LargeIcon, View.SmallIcon,
View.List, View.Details };
EventHandler eh = new EventHandler(MenuOnView);
for (int i = 0; i < 4; i++) {
MenuItemView miv = new MenuItemView();
miv.Text = astrView[i];
miv.View = aview[i];
miv.RadioCheck = true;
miv.Click += eh;
if (i == 3) // Default == View.Details
{
mivChecked = miv;
mivChecked.Checked = true;
filelist.View = mivChecked.View;
}
Menu.MenuItems[0].MenuItems.Add(miv);
}
Menu.MenuItems[0].MenuItems.Add("-");
MenuItem mi = new MenuItem("&Refresh",
new EventHandler(MenuOnRefresh), Shortcut.F5);
Menu.MenuItems[0].MenuItems.Add(mi);
}
void DirectoryTreeViewOnAfterSelect(object obj, TreeViewEventArgs tvea) {
filelist.ShowFiles(tvea.Node.FullPath);
}
void MenuOnView(object obj, EventArgs ea) {
mivChecked.Checked = false;
mivChecked = (MenuItemView)obj;
mivChecked.Checked = true;
filelist.View = mivChecked.View;
}
void MenuOnRefresh(object obj, EventArgs ea) {
}
}
class MenuItemView : MenuItem {
public View View;
}
ListView.Click
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
public class Form1 : Form
{
private System.Windows.Forms.ListView browserListView;
private System.Windows.Forms.Label currentLabel;
private System.Windows.Forms.Label displayLabel;
private System.Windows.Forms.ImageList fileFolder;
string currentDirectory = Directory.GetCurrentDirectory();
public Form1() {
InitializeComponent();
Image folderImage = Image.FromFile("winter.jpg" );
Image fileImage = Image.FromFile("winter.jpg" );
fileFolder.Images.Add( folderImage );
fileFolder.Images.Add( fileImage );
LoadFilesInDirectory( currentDirectory );
displayLabel.Text = currentDirectory;
}
private void browserListView_Click( object sender, EventArgs e )
{
if ( browserListView.SelectedItems.Count != 0 )
{
if ( browserListView.Items[0].Selected )
{
DirectoryInfo directoryObject = new DirectoryInfo( currentDirectory );
if ( directoryObject.Parent != null )
LoadFilesInDirectory( directoryObject.Parent.FullName );
}else {
string chosen = browserListView.SelectedItems[ 0 ].Text;
if ( Directory.Exists( currentDirectory + @"\" + chosen ) )
{
if ( currentDirectory == @"C:\" )
LoadFilesInDirectory( currentDirectory + chosen );
else
LoadFilesInDirectory(currentDirectory + @"\" + chosen );
}
}
displayLabel.Text = currentDirectory;
}
}
public void LoadFilesInDirectory( string currentDirectoryValue )
{
try
{
browserListView.Items.Clear();
browserListView.Items.Add( "Go Up One Level" );
currentDirectory = currentDirectoryValue;
DirectoryInfo newCurrentDirectory = new DirectoryInfo( currentDirectory );
DirectoryInfo[] directoryArray = newCurrentDirectory.GetDirectories();
FileInfo[] fileArray = newCurrentDirectory.GetFiles();
foreach ( DirectoryInfo dir in directoryArray )
{
ListViewItem newDirectoryItem = browserListView.Items.Add( dir.Name );
newDirectoryItem.ImageIndex = 0;
}
foreach ( FileInfo file in fileArray )
{
ListViewItem newFileItem = browserListView.Items.Add( file.Name );
newFileItem.ImageIndex = 1;
}
} catch ( UnauthorizedAccessException ) {
Console.WriteLine( "Unauthorized Access Exception");
}
}
private void InitializeComponent()
{
this.browserListView = new System.Windows.Forms.ListView();
this.fileFolder = new System.Windows.Forms.ImageList(new System.ruponentModel.Container());
this.currentLabel = new System.Windows.Forms.Label();
this.displayLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// browserListView
//
this.browserListView.Location = new System.Drawing.Point(12, 60);
this.browserListView.Name = "browserListView";
this.browserListView.Size = new System.Drawing.Size(456, 197);
this.browserListView.SmallImageList = this.fileFolder;
this.browserListView.TabIndex = 0;
this.browserListView.View = System.Windows.Forms.View.List;
this.browserListView.Click += new System.EventHandler(this.browserListView_Click);
//
// fileFolder
//
this.fileFolder.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.fileFolder.ImageSize = new System.Drawing.Size(16, 16);
this.fileFolder.TransparentColor = System.Drawing.Color.Transparent;
//
// currentLabel
//
this.currentLabel.AutoSize = true;
this.currentLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.currentLabel.Location = new System.Drawing.Point(10, 19);
this.currentLabel.Name = "currentLabel";
this.currentLabel.Size = new System.Drawing.Size(122, 20);
this.currentLabel.TabIndex = 1;
this.currentLabel.Text = "Now in Directory:";
//
// displayLabel
//
this.displayLabel.AutoSize = true;
this.displayLabel.Location = new System.Drawing.Point(138, 19);
this.displayLabel.Name = "displayLabel";
this.displayLabel.Size = new System.Drawing.Size(0, 0);
this.displayLabel.TabIndex = 2;
//
// ListViewTestForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(480, 270);
this.Controls.Add(this.displayLabel);
this.Controls.Add(this.currentLabel);
this.Controls.Add(this.browserListView);
this.Name = "ListViewTestForm";
this.Text = "ListViewTest";
this.ResumeLayout(false);
this.PerformLayout();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
ListView.ColumnClick
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form {
private System.Windows.Forms.ListView listView1 = new System.Windows.Forms.ListView();
private System.Windows.Forms.ColumnHeader Country= new System.Windows.Forms.ColumnHeader();
private System.Windows.Forms.ColumnHeader Capital= new System.Windows.Forms.ColumnHeader();
private System.Windows.Forms.ColumnHeader City_1= new System.Windows.Forms.ColumnHeader();
private System.Windows.Forms.ColumnHeader City_2= new System.Windows.Forms.ColumnHeader();
private System.Windows.Forms.Button REPORT= new System.Windows.Forms.Button();
private System.Windows.Forms.Button LIST= new System.Windows.Forms.Button();
private System.Windows.Forms.Button SMALLICON= new System.Windows.Forms.Button();
private System.Windows.Forms.Button LARGEICON= new System.Windows.Forms.Button();
ImageList ig = new ImageList();
private System.Windows.Forms.Button SELECTED= new System.Windows.Forms.Button();
private System.Windows.Forms.Button CHECKED= new System.Windows.Forms.Button();
private System.Windows.Forms.Panel panel1= new System.Windows.Forms.Panel();
public Form1() {
this.panel1.SuspendLayout();
this.SuspendLayout();
//
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.Size = new System.Drawing.Size(464, 152);
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(75, 0);
this.REPORT.Name = "REPORT";
this.REPORT.Size = new System.Drawing.Size(75, 24);
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(300, 0);
this.LIST.Name = "LIST";
this.LIST.Size = new System.Drawing.Size(75, 24);
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(150, 0);
this.SMALLICON.Name = "SMALLICON";
this.SMALLICON.Size = new System.Drawing.Size(75, 24);
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(375, 0);
this.LARGEICON.Name = "LARGEICON";
this.LARGEICON.Size = new System.Drawing.Size(75, 24);
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(75, 24);
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(225, 0);
this.CHECKED.Name = "CHECKED";
this.CHECKED.Size = new System.Drawing.Size(75, 24);
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(0, 157);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(464, 24);
this.panel1.TabIndex = 4;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(464, 181);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel1,
this.listView1});
this.Name = "Form1";
this.Text = "ListView";
this.Load += new System.EventHandler(this.Form1_Load);
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);
}
[STAThread]
static void Main() {
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e) {
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"));
listView1.SmallImageList = ig;
listView1.LargeImageList = ig;
listView1.Columns[1].TextAlign = HorizontalAlignment.Center;
listView1.Columns[2].TextAlign = HorizontalAlignment.Center;
listView1.Columns[3].TextAlign = HorizontalAlignment.Center;
string[] lv = new String[4];
lv[0] = "A";
lv[1] = "A1";
lv[2] = "A2";
lv[3] = "A3";
listView1.Items.Add(new ListViewItem(lv, 0));
lv[0] = "B";
lv[1] = "B1";
lv[2] = "B2";
lv[3] = "B3";
listView1.Items.Add(new ListViewItem(lv, 1));
lv[0] = "C";
lv[1] = "C1";
lv[2] = "C2";
lv[3] = "C3";
listView1.Items.Add(new ListViewItem(lv, 2));
lv[0] = "D";
lv[1] = "D1";
lv[2] = "D2";
lv[3] = "D3";
listView1.Items.Add(new ListViewItem(lv, 3));
lv[0] = "E";
lv[1] = "E1";
lv[2] = "E2";
lv[3] = "E3";
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.WriteLine(lvi.SubItems[i].Text);
}
}
}
private void REPORT_Click(object sender, System.EventArgs e) {
this.Text = "Report View";
listView1.View = View.Details;
}
private void LARGEICON_Click(object sender, System.EventArgs e) {
this.Text = "LargeIcon View";
listView1.View = View.LargeIcon;
}
private void SMALLICON_Click(object sender, System.EventArgs e) {
this.Text = "SmallIcon View";
listView1.View = View.SmallIcon;
}
private void LIST_Click(object sender, System.EventArgs e) {
this.Text = "List View";
listView1.View = View.List;
}
private void SELECTED_Click(object sender, System.EventArgs e) {
for (int k = 0; k < listView1.SelectedIndices.Count; k++) {
ListViewItem lvi = listView1.Items[listView1.SelectedIndices[k]];
for (int i = 0; i < lvi.SubItems.Count; i++) {
Console.WriteLine(lvi.SubItems[i].Text);
}
}
}
private void CHECKED_Click(object sender, System.EventArgs e) {
for (int k = 0; k < listView1.CheckedIndices.Count; k++) {
ListViewItem lvi = listView1.Items[listView1.CheckedIndices[k]];
for (int i = 0; i < lvi.SubItems.Count; i++) {
Console.WriteLine(lvi.SubItems[i].Text);
}
}
}
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.DragDrop
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form {
private System.Windows.Forms.ListView listView1= new System.Windows.Forms.ListView();
private System.Windows.Forms.ListView listView2= new System.Windows.Forms.ListView();
private System.ruponentModel.Container components = null;
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem("List 2 Item 1");
System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem("List 2 Item 2");
System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem("List 2 Item 3");
System.Windows.Forms.ListViewItem listViewItem4 = new System.Windows.Forms.ListViewItem("Item 1");
System.Windows.Forms.ListViewItem listViewItem5 = new System.Windows.Forms.ListViewItem("Item 2");
System.Windows.Forms.ListViewItem listViewItem6 = new System.Windows.Forms.ListViewItem("Item 3");
public Form1() {
this.SuspendLayout();
this.listView2.AllowDrop = true;
listViewItem1.UseItemStyleForSubItems = false;
listViewItem2.UseItemStyleForSubItems = false;
listViewItem3.UseItemStyleForSubItems = false;
this.listView2.Items.AddRange(new System.Windows.Forms.ListViewItem[]{
listViewItem1,listViewItem2,listViewItem3});
this.listView2.Location = new System.Drawing.Point(320, 24);
this.listView2.Size = new System.Drawing.Size(200, 216);
this.listView2.View = System.Windows.Forms.View.List;
this.listView2.DragDrop += new System.Windows.Forms.DragEventHandler(this.OnDragDrop);
this.listView2.DragEnter += new System.Windows.Forms.DragEventHandler(this.OnDragEnter);
this.listView1.AllowDrop = true;
listViewItem4.UseItemStyleForSubItems = false;
listViewItem5.UseItemStyleForSubItems = false;
listViewItem6.UseItemStyleForSubItems = false;
this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] { listViewItem4, listViewItem5, listViewItem6 });
this.listView1.Location = new System.Drawing.Point(40, 24);
this.listView1.Size = new System.Drawing.Size(200, 216);
this.listView1.View = System.Windows.Forms.View.List;
this.listView1.ItemDrag += new System.Windows.Forms.ItemDragEventHandler(this.OnItemDrag);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(576, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.listView2, this.listView1 });
this.ResumeLayout(false);
}
[STAThread]
static void Main() {
Application.Run(new Form1());
}
private void OnItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e) {
string s = e.Item.ToString();
DoDragDrop(s, DragDropEffects.Copy | DragDropEffects.Move);
}
private void OnDragEnter(object sender,
System.Windows.Forms.DragEventArgs e) {
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void OnDragDrop(object sender, System.Windows.Forms.DragEventArgs e) {
string typestring = "Type";
string s = e.Data.GetData(typestring.GetType()).ToString();
string orig_string = s;
s = s.Substring(s.IndexOf(":") + 1).Trim();
s = s.Substring(1, s.Length - 2);
this.listView2.Items.Add(s);
IEnumerator enumerator = listView1.Items.GetEnumerator();
int whichIdx = -1;
int idx = 0;
while (enumerator.MoveNext()) {
string s2 = enumerator.Current.ToString();
if (s2.Equals(orig_string)) {
whichIdx = idx;
break;
}
idx++;
}
this.listView1.Items.RemoveAt(whichIdx);
}
}
ListView.ItemActivate
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace ListView
{
public class Form1 : System.Windows.Forms.Form
{
private System.Collections.Specialized.StringCollection folderCol;
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();
// Init ListView and folder collection
folderCol = new System.Collections.Specialized.StringCollection();
CreateHeadersAndFillListView();
PaintListView(@"C:\");
folderCol.Add(@"C:\");
this.lwFilesAndFolders.ItemActivate += new System.EventHandler(this.lwFilesAndFolders_ItemActivate);
}
private void InitializeComponent()
{
// System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
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.SuspendLayout();
this.lblCurrentPath.Location = new System.Drawing.Point(16, 8);
this.lblCurrentPath.Name = "lblCurrentPath";
this.lblCurrentPath.Size = new System.Drawing.Size(528, 16);
this.lblCurrentPath.TabIndex = 3;
//
// ilLarge
//
this.ilLarge.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.ilLarge.ImageSize = new System.Drawing.Size(32, 32);
// 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(16, 16);
// 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(16, 32);
this.lwFilesAndFolders.MultiSelect = false;
this.lwFilesAndFolders.Name = "lwFilesAndFolders";
this.lwFilesAndFolders.Size = new System.Drawing.Size(400, 216);
this.lwFilesAndFolders.SmallImageList = this.ilSmall;
this.lwFilesAndFolders.TabIndex = 0;
this.lwFilesAndFolders.View = System.Windows.Forms.View.List;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(552, 293);
this.Controls.AddRange(new System.Windows.Forms.Control[] {this.lblCurrentPath, this.lwFilesAndFolders});
this.Name = "Form1";
this.Text = "ListView";
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(string root)
{
try
{
ListViewItem lvi;
ListViewItem.ListViewSubItem lvsi;
this.lblCurrentPath.Text = root + " (Double click to display the path name)";
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(root);
DirectoryInfo[] dirs = dir.GetDirectories();
FileInfo[] files = dir.GetFiles();
this.lwFilesAndFolders.Items.Clear();
this.lwFilesAndFolders.BeginUpdate();
foreach (System.IO.DirectoryInfo di in dirs)
{
lvi = new ListViewItem();
lvi.Text = di.Name;
//lvi.ImageIndex = 0;
lvi.Tag = di.FullName;
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = "sub item";
lvi.SubItems.Add(lvsi);
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = di.LastAccessTime.ToString();
lvi.SubItems.Add(lvsi);
this.lwFilesAndFolders.Items.Add(lvi);
}
this.lwFilesAndFolders.EndUpdate();
}
catch (System.Exception err)
{
MessageBox.Show("Error: " + err.Message);
}
this.lwFilesAndFolders.View = View.Details;
}
private void lwFilesAndFolders_ItemActivate(object sender, System.EventArgs e)
{
System.Windows.Forms.ListView lw = (System.Windows.Forms.ListView)sender;
string filename = lw.SelectedItems[0].Tag.ToString();
Console.WriteLine(filename);
}
}
}
ListView.Items
using System;
using System.Windows.Forms;
using System.IO;
public class TagPropertyExample : System.Windows.Forms.Form {
ListView listView = new ListView();
public TagPropertyExample () {
listView.Left = 10;
listView.Top = 10;
listView.Size = new System.Drawing.Size(292, 273);
DirectoryInfo directory = new DirectoryInfo("C:\\");
FileInfo[] files = directory.GetFiles();
foreach (FileInfo file in files) {
ListViewItem item = listView.Items.Add(file.Name);
item.ImageIndex = 0;
item.Tag = file;
}
this.Controls.Add(listView);
}
public static void Main(){
Application.Run(new TagPropertyExample());
}
}
ListView.LargeImageList
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace ListView
{
public class Form1 : System.Windows.Forms.Form
{
private System.Collections.Specialized.StringCollection folderCol;
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();
// Init ListView and folder collection
folderCol = new System.Collections.Specialized.StringCollection();
CreateHeadersAndFillListView();
PaintListView(@"C:\");
folderCol.Add(@"C:\");
this.lwFilesAndFolders.ItemActivate += new System.EventHandler(this.lwFilesAndFolders_ItemActivate);
}
private void InitializeComponent()
{
// System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
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.SuspendLayout();
this.lblCurrentPath.Location = new System.Drawing.Point(16, 8);
this.lblCurrentPath.Name = "lblCurrentPath";
this.lblCurrentPath.Size = new System.Drawing.Size(528, 16);
this.lblCurrentPath.TabIndex = 3;
//
// ilLarge
//
this.ilLarge.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.ilLarge.ImageSize = new System.Drawing.Size(32, 32);
// 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(16, 16);
// 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(16, 32);
this.lwFilesAndFolders.MultiSelect = false;
this.lwFilesAndFolders.Name = "lwFilesAndFolders";
this.lwFilesAndFolders.Size = new System.Drawing.Size(400, 216);
this.lwFilesAndFolders.SmallImageList = this.ilSmall;
this.lwFilesAndFolders.TabIndex = 0;
this.lwFilesAndFolders.View = System.Windows.Forms.View.List;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(552, 293);
this.Controls.AddRange(new System.Windows.Forms.Control[] {this.lblCurrentPath, this.lwFilesAndFolders});
this.Name = "Form1";
this.Text = "ListView";
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(string root)
{
try
{
ListViewItem lvi;
ListViewItem.ListViewSubItem lvsi;
this.lblCurrentPath.Text = root + " (Double click to display the path name)";
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(root);
DirectoryInfo[] dirs = dir.GetDirectories();
FileInfo[] files = dir.GetFiles();
this.lwFilesAndFolders.Items.Clear();
this.lwFilesAndFolders.BeginUpdate();
foreach (System.IO.DirectoryInfo di in dirs)
{
lvi = new ListViewItem();
lvi.Text = di.Name;
//lvi.ImageIndex = 0;
lvi.Tag = di.FullName;
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = "sub item";
lvi.SubItems.Add(lvsi);
lvsi = new ListViewItem.ListViewSubItem();
lvsi.Text = di.LastAccessTime.ToString();
lvi.SubItems.Add(lvsi);
this.lwFilesAndFolders.Items.Add(lvi);
}
this.lwFilesAndFolders.EndUpdate();
}
catch (System.Exception err)
{
MessageBox.Show("Error: " + err.Message);
}
this.lwFilesAndFolders.View = View.Details;
}
private void lwFilesAndFolders_ItemActivate(object sender, System.EventArgs e)
{
System.Windows.Forms.ListView lw = (System.Windows.Forms.ListView)sender;
string filename = lw.SelectedItems[0].Tag.ToString();
Console.WriteLine(filename);
}
}
}
ListView.MouseUp
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
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.ruboBox cbView;
private System.Windows.Forms.Label lblAbbreviation;
private System.ruponentModel.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.ruponents = new System.ruponentModel.Container();
this.lvCountries = new System.Windows.Forms.ListView();
this.imgLarge = new System.Windows.Forms.ImageList(this.ruponents);
this.imgSmall = new System.Windows.Forms.ImageList(this.ruponents);
this.cbView = new System.Windows.Forms.ruboBox();
this.lblAbbreviation = new System.Windows.Forms.Label();
this.SuspendLayout();
this.lvCountries.LargeImageList = this.imgLarge;
this.lvCountries.Location = new System.Drawing.Point(24, 72);
this.lvCountries.Name = "lvCountries";
this.lvCountries.Size = new System.Drawing.Size(256, 248);
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(48, 48);
this.imgLarge.TransparentColor = System.Drawing.Color.Transparent;
this.imgSmall.ColorDepth = System.Windows.Forms.ColorDepth.Depth16Bit;
this.imgSmall.ImageSize = new System.Drawing.Size(16, 16);
this.imgSmall.TransparentColor = System.Drawing.Color.Transparent;
//
// cbView
//
this.cbView.Location = new System.Drawing.Point(32, 32);
this.cbView.Name = "cbView";
this.cbView.Size = new System.Drawing.Size(128, 21);
this.cbView.TabIndex = 1;
this.cbView.SelectedIndexChanged += new System.EventHandler(this.cbView_SelectedIndexChanged);
//
// lblAbbreviation
//
this.lblAbbreviation.Location = new System.Drawing.Point(176, 32);
this.lblAbbreviation.Name = "lblAbbreviation";
this.lblAbbreviation.Size = new System.Drawing.Size(48, 23);
this.lblAbbreviation.TabIndex = 2;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(312, 339);
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;}
}
}
ListView.Sorting
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader lvcState;
private System.Windows.Forms.ColumnHeader lvcCapital;
public Form1()
{
InitializeComponent();
listView1.Items.Add (new ListViewItem (new string[]{"a","d"}));
listView1.Items.Add (new ListViewItem (new string[]{"b","c"}));
listView1.Items.Add (new ListViewItem (new string[]{"c","b"}));
listView1.Items.Add (new ListViewItem (new string[]{"d","a"}));
listView1.View = View.Details;
}
private void InitializeComponent()
{
this.listView1 = new System.Windows.Forms.ListView();
this.lvcState = new System.Windows.Forms.ColumnHeader();
this.lvcCapital = new System.Windows.Forms.ColumnHeader();
this.SuspendLayout();
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.lvcState,
this.lvcCapital});
this.listView1.FullRowSelect = true;
this.listView1.Location = new System.Drawing.Point(0, 32);
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(292, 160);
this.listView1.Sorting = System.Windows.Forms.SortOrder.Descending;
this.listView1.TabIndex = 3;
this.listView1.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.listView1_OnColumnClick);
this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_OnSelectedIndexChanged);
//
// lvcState
//
this.lvcState.Text = "State Name";
this.lvcState.Width = 120;
//
// lvcCapital
//
this.lvcCapital.Text = "Capital City";
this.lvcCapital.Width = 120;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.AddRange(new System.Windows.Forms.Control[] { this.listView1,
});
this.MinimumSize = new System.Drawing.Size(300, 300);
this.Name = "Form1";
this.Text = "The State Flags";
this.ResumeLayout(false);
}
static void Main()
{
Application.Run(new Form1());
}
private void listView1_OnColumnClick(object sender, System.Windows.Forms.ColumnClickEventArgs e)
{
ListViewSorter Sorter = new ListViewSorter();
listView1.ListViewItemSorter = Sorter;
if (!(listView1.ListViewItemSorter is ListViewSorter))
return;
Sorter = (ListViewSorter) listView1.ListViewItemSorter;
if (Sorter.LastSort == e.Column)
{
if (listView1.Sorting == SortOrder.Ascending)
listView1.Sorting = SortOrder.Descending;
else
listView1.Sorting = SortOrder.Ascending;
}
else{
listView1.Sorting = SortOrder.Descending;
}
Sorter.ByColumn = e.Column;
listView1.Sort ();
}
private void listView1_OnSelectedIndexChanged(object sender, System.EventArgs e)
{
if (listView1.SelectedItems.Count == 0)
{
return;
}
string State = listView1.SelectedItems[0].SubItems[0].Text;
string Capital = listView1.SelectedItems[0].SubItems[1].Text;
if (State.Length > 0)
{
Console.WriteLine(State + " " + Capital);
}
}
}
public class ListViewSorter : System.Collections.IComparer
{
public int Compare (object o1, object o2)
{
if (!(o1 is ListViewItem))
return (0);
if (!(o2 is ListViewItem))
return (0);
ListViewItem lvi1 = (ListViewItem) o2;
string str1 = lvi1.SubItems[ByColumn].Text;
ListViewItem lvi2 = (ListViewItem) o1;
string str2 = lvi2.SubItems[ByColumn].Text;
int result;
if (lvi1.ListView.Sorting == SortOrder.Ascending)
result = String.rupare (str1, str2);
else
result = String.rupare (str2, str1);
LastSort = ByColumn;
return (result);
}
public int ByColumn
{
get {return Column;}
set {Column = value;}
}
int Column = 0;
public int LastSort
{
get {return LastColumn;}
set {LastColumn = value;}
}
int LastColumn = 0;
}
ListView.View
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
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(424, 32);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(120, 128);
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(8, 96);
this.rdoDetails.Name = "rdoDetails";
this.rdoDetails.Size = new System.Drawing.Size(104, 16);
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(8, 72);
this.rdoList.Name = "rdoList";
this.rdoList.Size = new System.Drawing.Size(104, 16);
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(8, 48);
this.rdoSmall.Name = "rdoSmall";
this.rdoSmall.Size = new System.Drawing.Size(104, 16);
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(8, 24);
this.rdoLarge.Name = "rdoLarge";
this.rdoLarge.Size = new System.Drawing.Size(96, 16);
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(32, 32);
// 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(16, 16);
// 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(16, 32);
this.lwFilesAndFolders.MultiSelect = false;
this.lwFilesAndFolders.Name = "lwFilesAndFolders";
this.lwFilesAndFolders.Size = new System.Drawing.Size(400, 216);
this.lwFilesAndFolders.SmallImageList = this.ilSmall;
this.lwFilesAndFolders.TabIndex = 0;
this.lwFilesAndFolders.View = System.Windows.Forms.View.List;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(552, 293);
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;
}
}
}