Binding images to the treelist node of devexpress

Source: Internet
Author: User

 

Recently, the treelist control in DX was used in the project to display the characteristic pictures before each node when it was bound to the data source. The following describes how to check related materials:
1. First open vs2010 to create a winfrom ApplicationProgram;

2. Add the treelist control in dx in the winfrom application. For example:

3. Bind the data source of the treelist control when loading the form;

     Private   Void Form1_load ( Object  Sender, eventargs e) {datatable dt = New  Datatable (); DT. Columns. Add (  "  ID  " ,Typeof ( Int  ); DT. Columns. Add (  "  Name  " , Typeof ( String  ); DT. Columns. Add (  "  Parentid  " , Typeof ( Int  ); DT. Rows. Add ( 1 , "  Shandong Province  " , 1  ); DT. Rows. Add (  11 , "  Jinan  " , 1  ); DT. Rows. Add (  12 , "  Tai'an  " ,1  ); DT. Rows. Add (  13 , "  Jining  " , 1  ); DT. Rows. Add (  14 , "  Heze  " , 1  ); Treelistdemo. keyfieldname = " ID  "  ; Treelistdemo. parentfieldname = "  Parentid  "  ; Treelistdemo. datasource = DT ;} 

4. Add the imagelist control in the winfrom control to the form and set the images attribute of the control. Use the selectimagelist attribute in the treelist control to set it to the imagelist control;

5. Add the treelistdemo_getselectimage (Object sender, devexpress. xtratreelist. getselectimageeventargs e) event to the treelist control;

 

         Private   Void Treelistdemo_getselectimage ( Object  Sender, devexpress. xtratreelist. getselectimageeventargs e ){  If (E. node = Null ) Return  ; Treelistnode Node = E. node;  Int Id = ( Int ) Node. getvalue ( "  ID  " );  If (ID = 1  ) E. nodeimageindex = 0  ;  Else  E. nodeimageindex = 1  ;} 

CodeE. nodeimageindex is the index of the image set in imagelist;

Running effect:

 

 

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.