ListView Control Implementation Form Code _c# tutorial in C #

Source: Internet
Author: User

No more nonsense to say, directly to everyone to paste the key code.

The specific code looks like this:

Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Windows.Forms;  namespace WindowsFormsApplication1 {public partial class Form1:form {public Form1 () {InitializeComponent ();} private void Form1_Load (object sender, EventArgs e) {//Set the ListView associated ImageList listview1.largeimagelist = ImageList2; listView1 .
SmallImageList = ImageList1;
Display detailed information Listview1.view = view.details;
Add Group ListViewGroup LG1 = new ListViewGroup (); Lg1.
Header = "a group"; Lg1.
Name = "one";
LISTVIEW1.GROUPS.ADD (LG1);
ListViewGroup lg2 = new ListViewGroup (); Lg2.
Header = "two groups"; Lg2.
Name = "two";
LISTVIEW1.GROUPS.ADD (LG2);
Add Column LISTVIEW1.COLUMNS.ADD ("Code");
LISTVIEW1.COLUMNS.ADD ("name");
LISTVIEW1.COLUMNS.ADD ("Birthday");
Select Entire Row listview1.fullrowselect = true;
Show checkbox listview1.checkboxes = true;
Add items, listview each piece of data is called a infoda da = new Infoda (); list<info> list = da. SelecT (); foreach (Info data in list) {//create item ListViewItem Zhuxiang = new ListViewItem (); Zhuxiang. Text = data.
Code; Zhuxiang.
ImageIndex = 0; Zhuxiang.
Group = Listview1.groups[0];
Listviewitem.listviewsubitem zi1 = new Listviewitem.listviewsubitem (); Zi1. Text = data.
Name; Zhuxiang.
SubItems.Add (ZI1);
Listviewitem.listviewsubitem zi2 = new Listviewitem.listviewsubitem (); Zi2. Text = data.
Birthday.tostring ("Yyyy-mm-dd");; Zhuxiang.
SubItems.Add (ZI2);
Add Item listView1.Items.Add (Zhuxiang); foreach (Info data in list) {//create item ListViewItem Zhuxiang = new ListViewItem (); Zhuxiang. Text = data.
Code; Zhuxiang.
ImageIndex = 1; Zhuxiang.
Group = listview1.groups[1];
Listviewitem.listviewsubitem zi1 = new Listviewitem.listviewsubitem (); Zi1. Text = data.
Name; Zhuxiang.
SubItems.Add (ZI1);
Listviewitem.listviewsubitem zi2 = new Listviewitem.listviewsubitem (); Zi2. Text = data.
Birthday.tostring ("Yyyy-mm-dd");; Zhuxiang.
SubItems.Add (ZI2);
Add Item listView1.Items.Add (Zhuxiang); }} private void button1_Click (object sender, EventArgs e) {listview1.view = view.details;} private void Button2_Click (object sender, EventArgs E {Listview1.view = View.LargeIcon} private void Button3_Click (object sender, EventArgs e) {Listview1.view = View.smal
Licon; } private void Button4_Click (object sender, EventArgs e) {if (ListView1.SelectedItems.Count > 0) {MessageBox.Show (LIS Tview1.selecteditems[0].
Text); } private void Button5_click (object sender, EventArgs e) {//listview1.checkboxes = true;} private void Button6_click (o
Bject sender, EventArgs e) {string s = ""; foreach (ListViewItem item in Listview1.checkeditems) {s + + item.
text+ "--";
} MessageBox.Show (s); }
}
}

The above is a small part of the introduction of C # ListView control to implement the form code, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.