本文整理汇总了C#中System.Windows.Forms.ListView.View属性的典型用法代码示例。如果您正苦于以下问题:C# ListView.View属性的具体用法?C# ListView.View怎么用?C# ListView.View使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.ListView
的用法示例。
在下文中一共展示了ListView.View属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMyListView
private void CreateMyListView()
{
// Create a new ListView control.
ListView listView1 = new ListView();
listView1.Bounds = new Rectangle(new Point(10,10), new Size(300,200));
// Set the view to show details.
listView1.View = View.Details;
// Allow the user to edit item text.
listView1.LabelEdit = true;
// Allow the user to rearrange columns.
listView1.AllowColumnReorder = true;
// Display check boxes.
listView1.CheckBoxes = true;
// Select the item and subitems when selection is made.
listView1.FullRowSelect = true;
// Display grid lines.
listView1.GridLines = true;
// Sort the items in the list in ascending order.
listView1.Sorting = SortOrder.Ascending;
// Create three items and three sets of subitems for each item.
ListViewItem item1 = new ListViewItem("item1",0);
// Place a check mark next to the item.
item1.Checked = true;
item1.SubItems.Add("1");
item1.SubItems.Add("2");
item1.SubItems.Add("3");
ListViewItem item2 = new ListViewItem("item2",1);
item2.SubItems.Add("4");
item2.SubItems.Add("5");
item2.SubItems.Add("6");
ListViewItem item3 = new ListViewItem("item3",0);
// Place a check mark next to the item.
item3.Checked = true;
item3.SubItems.Add("7");
item3.SubItems.Add("8");
item3.SubItems.Add("9");
// Create columns for the items and subitems.
// Width of -2 indicates auto-size.
listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left);
listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center);
//Add the items to the ListView.
listView1.Items.AddRange(new ListViewItem[]{item1,item2,item3});
// Create two ImageList objects.
ImageList imageListSmall = new ImageList();
ImageList imageListLarge = new ImageList();
// Initialize the ImageList objects with bitmaps.
imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage1.bmp"));
imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage2.bmp"));
imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage1.bmp"));
imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage2.bmp"));
//Assign the ImageList objects to the ListView.
listView1.LargeImageList = imageListLarge;
listView1.SmallImageList = imageListSmall;
// Add the ListView to the control collection.
this.Controls.Add(listView1);
}
示例2: Form1
//引入命名空间
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(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;
}
}
}