Scenes
Winform controls -DevExpress18 download and install the registration and use in VS:
https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100061243
In the above installation Treelist used up its controls on the basis of DevExpress.
List then you can create a new data source, and assigned to TreeList.
effect
achieve
New Winform program, and then drag a TreeList
New Data source class TreeNode
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DevExpressSimple { class TreeNode { //标识Id private string id; //父级节点ID private string parentId; //节点显示文本 private string nodeText; public string NodeText { get { return nodeText; } set { nodeText = value; } } public string ParentId { get { return parentId; } set { parentId = value; } } public string Id { get { return id; } set { id = value; } } } }
Double-click the form into the load event of the form.
private void Form1_Load(object sender, EventArgs e) { string keyFieldName = "Id"; string parentFieldName = "ParentId"; //新建list数据源 List<TreeNode> data = new List<TreeNode>(); data.Add(new TreeNode() { Id = "root", ParentId = String.Empty, NodeText = "测试1" }); data.Add(new TreeNode() { Id = " First " , the ParentId = " the root " , NodeText = " Test 2 " }); // column DevExpress.XtraTreeList.Columns.TreeListColumn colNode = new new DevExpress.XtraTreeList.Columns.TreeListColumn (); // Set the name colNode.Name = " name " ; // set the title colNode.Caption = " title " ; // set the allocation from the data source to the field name of the current column. = colNode.FieldName " NodeText "; // set the display position of the tree in the list of the current column. = colNode.VisibleIndex 0 ; // is visible colNode.Visible = to true ; // if editing is allowed colNode.OptionsColumn.AllowEdit = to false ; // whether to allow the mobile colNode.OptionsColumn.AllowMove = to false ; // if allowed to move to the custom form colNode.OptionsColumn.AllowMoveToCustomizationForm = to false ; // whether to allow sorting colNode.OptionsColumn.AllowSort = to false; // if fixed column width colNode.OptionsColumn.FixedWidth = to false ; // if read only colNode.OptionsColumn.ReadOnly = to true ; // whether to allow the display in a custom form after removal column colNode.OptionsColumn.ShowInCustomizationForm = to true ; // to clear the column the this .treeList1.Columns.Clear (); // the array of columns added to the end of the collection. the this .treeList1.Columns.AddRange ( new new DevExpress.XtraTreeList.Columns.TreeListColumn [] {} colNode); #region binding data source //ParentFieldName set properties KeyFieldName // set a value that specifies bound to a data source control key field XtratreeList the this .treeList1.KeyFieldName = keyFieldName; // set a value that represents the data recorded in the parent data source to identify this source field. the this .treeList1.ParentFieldName = ParentFieldName; the this .treeList1.DataSource = Data; // refresh data of the this .treeList1.RefreshDataSource (); #endregion }
Note:
1.list is to display the data source, wherein the Id attribute flag is specified parent node another node.
Id attribute is specified 2.ParentId parent node, the corresponding node, and if the root node, the parent node is empty.
3.NodeText is the node text to be displayed.
4. After the assignment to the list, but also to tell TreeList corresponding relationship, you need to set the two properties treelist
KeyFiledName and ParentFiledName. Wherein KeyFiledName specified bound to a data source control key field, Id is specified above, i.e., the node as a field marker.
ParentFiledName data source field is a sign of this data source parent record.
The column is then also used TreeListColumn new objects, attributes related to set the column number, which field is assigned to also take this column from the data source specified by FieldName.
6. More properties directly in the source code by viewing the source property acquisition.
Source download
https://download.csdn.net/download/badao_liumang_qizhi/11614224