C # preliminary usage of the winform treelistview Control

Source: Internet
Author: User

Treelistview is a third-party control. I found the source code under vs2003 and upgraded it to vs2010.
There is no difference in use. I just used it. It feels pretty good. Share it.

1. Add the treelistview control to the toolbox.
Right-click the General tab in the toolbox and select an item. Find system. Windows. Forms. treelistview. dll.
Add in. Then you can drag a form like a normal control.
2. Set properties here we mainly set the columns set and smallimagelist
Set to display the node icon. If the smallimagelist attribute is not set, it cannot be displayed normally.
If no icon is set, the position of the icon is blank.
The checkboxs attribute can be set to recursive and can be displayed as a check box.
3. Add a small item through additems,
Compile beforeexpand (); beforecollapse (); beforelabeledit ();
Three event response functions. It is the icon displayed when it is expanded or collapsed.
4. The source code of treelistview is included for secondary development.

Meteorology

Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. text;
Using System. Windows. forms;

NamespaceTreelistviewapp
{
Public Partial ClassForm1: Form
{
PublicForm1 ()
{
Initializecomponent ();
}

Private   Void Form1_load ( Object Sender, eventargs E)
{
Additems ();
}
Private   Void Additems ()
{
// The first parameter is the text to be displayed, and the second parameter is the icon index to be displayed.
Treelistviewitem itema =   New Treelistviewitem ( " A " , 0 );
Itema. Expand (); // Expand
Itema. subitems. Add ( " AA " ); // Subitems is equivalent to different column values of the same row.
Itema. subitems. Add ( " Bb " ); // Column 3
// Level 2
Treelistviewitem itema0 =   New Treelistviewitem ( " A0 " , 1 );
Itema. Items. Add (itema0 );
// Level 3
Treelistviewitem itema00 =   New Treelistviewitem ( " A00 " , 3 );
Itema0.items. Add (itema00 );

Treelistview1.items. Add (itema );
}
// Collapse event
Private   Void Treelistviewdomainbeforecollapse ( Object Sender, treelistviewcanceleventargs E)
{
// Index 1 and 2 correspond to the collapsed and expanded icons respectively.
If (E. Item. imageindex =   2 ) E. Item. imageindex =   1 ;
}
// Show events
Private   Void Treelistviewinclubeforeexpand ( Object Sender, treelistviewcanceleventargs E)
{
If (E. Item. imageindex =   1 ) E. Item. imageindex =   2 ;
}
// Edit status
Private   Void Treelistviewdomainbeforelabeledit ( Object Sender, treelistviewbeforelabelediteventargs E)
{
// Enable the labeledit attribute only when the labeledit attribute is set to true.
If (E. Item. imageindex <   1   | E. Item. imageindex >   2 ) // Level 1 and level 3 can only edit the first column.
E. columnindex =   0 ;
If (E. columnindex =   1 ) // For the second column, a drop-down box is displayed.
{
ComboBox =   New ComboBox ();
ComboBox. Items. addrange ( New   String [] { " New value 1 " , " New Value 2 " , " New Value 3 " });
E. Editor = ComboBox;
}
}
}
}

Source code download: http://files.cnblogs.com/greatverve/TreeListViewApp.rar

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.