1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace ComboBox_ListView 11 { 12 public partial class Form1 : Form 13 { 14 public Form1() 15 { 16 InitializeComponent(); 17 } 18 19 private void Form1_Load(object sender, EventArgs e) 20 { 21 // comboBox1绑定数据源 22 comboBox1.DataSource = Enum.GetNames(typeof(View)); 23 24 // 为listView1指定大图标控件 25 listView1.LargeImageList = imageList1; 26 // 为listView1指定小图标控件 27 listView1.SmallImageList = imageList2; 28 29 } 30 31 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) 32 { 33 34 listView1.Items.Clear(); 35 // 获取当前系统进程 36 string[] processess = System.Diagnostics.Process.GetProcesses().Select(p => p.ProcessName).ToArray(); 37 38 // 将进程加入到listView1控件的Items中, p为单一进程名称, 0 为ImageList中图片资源的索引 39 // 写法1: 40 foreach (string p in processess) 41 { 42 listView1.Items.Add(p, 0); 43 } 44 45 //// 写法2: 46 //Array.ForEach(processess, p=>listView1.Items.Add(p,0)); 47 48 //// 写法3: 49 //Array.ForEach(processess, p => listView1.Items.Add(new ListViewItem(p, 0))); 50 51 // 列表框选择项改变时试着ListView控件的视图效果: 大图标/ 小图标/ 列表 等等 52 listView1.View = (View)Enum.Parse(typeof(View), comboBox1.Text); 53 54 } 55 56 } 57 58 }