C # form LISTVIEW,

Source: Internet
Author: User

C # form LISTVIEW,

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. threading. tasks; 9 using System. windows. forms; 10 11 namespace WindowsFormsApplication1 12 {13 public partial class Form1: Form 14 {15 public Form1 () 16 {17 InitializeComponent (); 18} 19 20 private void Form1_Load (object sender, eventArgs e) 21 {22 23 24 // set imagelist 25 listView1.LargeImageList = imageList2; 26 listView1.SmallImageList = imageList1; 27 28 // display details 29 listView1.View = View. details; 30 31 // Add group 32 ListViewGroup lg1 = new ListViewGroup (); 33 lg1.Header = "group"; 34 lg1.Name = "one"; 35 listView1.Groups. add (lg1); 36 ListViewGroup lg2 = new ListViewGroup (); 37 lg2.Header = "group 2"; 38 lg2.Name = "two"; 39 listView1.Groups. add (lg2); 40 41 // Add column 42 listView1.Columns. add ("Code"); 43 listView1.Columns. add ("name"); 44 listView1.Columns. add ("Birthday"); 45 46 // select the entire row 47 listView1.FullRowSelect = true; 48 49 // display checkbox 50 listView1.CheckBoxes = true; 51 52 // Add the item, each piece of listview data is called a 53 InfoDA da = new InfoDA (); 54 List <Info> list = da. select (); 55 56 foreach (Info data in list) 57 {58 // master item 59 ListViewItem zhuxiang = new ListViewItem (); 60 zhuxiang. text = data. code; 61 zhuxiang. imageIndex = 0; 62 zhuxiang. group = listView1.Groups [0]; 63 64 // create item 65 ListViewItem. listViewSubItem zi1 = new ListViewItem. listViewSubItem (); 66 zi1.Text = data. name; 67 zhuxiang. subItems. add (zi1); 68 69 ListViewItem. listViewSubItem zi2 = new ListViewItem. listViewSubItem (); 70 zi2.Text = data. birthday. toString ("yyyy-MM-dd"); 71 zhuxiang. subItems. add (zi2); 72 73 74 // Add Item 75 listView1.Items. add (zhuxiang); 76 77} 78 79 80 foreach (Info data in list) 81 {82 // master creation item 83 ListViewItem zhuxiang = new ListViewItem (); 84 zhuxiang. text = data. code; 85 zhuxiang. imageIndex = 1; 86 zhuxiang. group = listView1.Groups [1]; 87 88 // create Item 89 ListViewItem. listViewSubItem zi1 = new ListViewItem. listViewSubItem (); 90 zi1.Text = data. name; 91 zhuxiang. subItems. add (zi1); 92 93 ListViewItem. listViewSubItem zi2 = new ListViewItem. listViewSubItem (); 94 zi2.Text = data. birthday. toString ("yyyy-MM-dd"); 95 zhuxiang. subItems. add (zi2); 96 97 98 // Add item 99 listView1.Items. add (zhuxiang); 100 101 102} 103 104 105} 106 private void button#click (object sender, EventArgs e) 107 {108 listView1.View = View. details; 109} 110 111 private void button2_Click (object sender, EventArgs e) 112 {113 listView1.View = View. largeIcon; 114} 115 116 private void button3_Click (object sender, EventArgs e) 117 {118 listView1.View = View. smallIcon; 119} 120 121 private void button4_Click (object sender, EventArgs e) 122 {123 if (listView1.SelectedItems. count> 0) 124 {125 MessageBox. show (listView1.SelectedItems [0]. text); 126} 127} 128 129 private void button5_Click (object sender, EventArgs e) 130 {131 // listView1.CheckBoxes = true; 132} 133 134 private void button6_Click (object sender, eventArgs e) 135 {136 string s = ""; 137 138 foreach (ListViewItem item in listView1.CheckedItems) 139 {140 s + = item. text + "--"; 141} 142 143 MessageBox. show (s); 144} 145} 146}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.