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: