[C # Control Learning 1] Treeview listview

Source: Internet
Author: User

I suddenly wanted to use C # as an interface, but I never used C # as an interface. So let's take a look at the use of the control and lay the foundation for a tool.

Listview:

1. add an item to listview:

Listviewitem TMP = new listviewitem ("1111 ");
Listviewitem tmp1 = new listviewitem ("2222", 0 );
Listview1.items. Add (TMP );

Listview1.items. Add (tmp1 );

If you want to add an imagelist control for a graph, add an image, and set the largeimagelist attribute of listview to the newly added imagelist control, you can display the image.

 

2. Right-click the list menu:

Add a contextmenustrip control and set the contextmenistrip attribute of the listview control to the right-click menu control. However, if you click a blank area of the listview, the menu does not need to be displayed, add the following to the contextmenustrip opening method:

If (listview1.selecteditems. Count <= 0)
{
E. Cancel = true;
}

You can.

 

 

 

Treeview:

1. Add a node:

Treenode rootnode = new treenode (STR );
Treeview1.nodes. Add (rootnode );

Example:

Add the node from last Saturday to today, and use each day as a node.

 

Int COUNT = 0;
Datetime today = datetime. now;
Switch (today. dayofweek)
{
Case dayofweek. Saturday:
Count = 1;
Break;

Case dayofweek. Sunday:
Count = 2;
Break;

Case dayofweek. Monday:
Count = 3;
Break;

Case dayofweek. Tuesday:
Count = 4;
Break;

Case dayofweek. Wednesday:
Count = 5;
Break;

Case dayofweek. Thursday:
Count = 6;
Break;

Case dayofweek. Friday:
Count = 7;
Break;
}

 

Datetime today1 = datetime. now;
For (INT I = 0; I <count; I ++)
{
String [] Date = today1.adddays (-I). Date. tostring (). Split ('');
String STR = string. Format ("{0} {1}", date [0], today1.adddays (-I). dayofweek. tostring ());
Treenode rootnode = new treenode (STR );
Treeview1.nodes. Add (rootnode );
}

 

 

 

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.