文件名称:ListView(列表视图)
文件大小:956B
文件格式:SLN
更新时间:2011-12-29 15:34:59
列表视图
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace ListView_列表视图_ { public partial class Form1 : Form { public Form1() { InitializeComponent(); } static int itemNumber = 0;int a = 0; private void button1_Click(object sender, EventArgs e) { //构造条目的子条目字符串数组 String[] subItem = new String[] { textBox1.Text, textBox2.Text, textBox3.Text }; //插入新的条目 listView1.Items.Add(new ListViewItem(subItem)); listView1.Items[itemNumber].ImageIndex = a; itemNumber++; a++; if (a >= 12) { a = 0; } textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; } private void button2_Click(object sender, EventArgs e) { for(int i=listView1.SelectedItems.Count-1;i>=0;i--) { //获取当前选中的条目之一 ListViewItem li = listView1.SelectedItems[i]; //删除这个条目 listView1.Items.Remove(li); itemNumber--; } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { string selStr = comboBox1.SelectedItem.ToString(); switch (selStr) { case "大图标": listView1.View = View.LargeIcon; break; case "小图标": listView1.View = View.SmallIcon; break; case "列表": listView1.View = View.List; break; case "报告": listView1.View = View.Details; break; } } } }