Application of treelist in Dev (rpm)

Source: Internet
Author: User
Tags dname

Use Treelist If you need to add a cell if you are simply reading data or retrieving data Gridcontrol

1. If you click Add, add the Treelist node:

protected internal void btnAdd_Click (object sender, EventArgs e) {if (TreeList1.Nodes.Count = = 0) {treelistnode node = t Reelist1.appendnode (new object[] {0},-1); multiple parameters can be written in the//array, but each parameter represents a column } else {int dy = Convert.ToInt32 (TreeList1.Nodes.LastNode.GetValue ("CID")); //Get last Node ID Treelistnode node = treelist1.appendnode (new object[] {dy + 1},-1); }

}

2. Cport = Treelist1.nodes[i]. Getdisplaytext ("Cport"). ToString (). Trim (); //Gets the text in the cell, Cport represents the column name

BOOL Falge = Convert.toboolean (Treelist1.nodes[i]. GetValue ("Cflage")); //Gets the value of the check box, Cflage represents the column name

3. Delete the selected node

<summary>///Last selected node///</summary> Treelistnode Deletenode;

private void Treelist1_afterfocusnode (object sender, DevExpress.XtraTreeList.NodeEventArgs e) {deletenode =e.node;// Get the last ID

}

public void Btndel_click (object sender, EventArgs e) {

This.treeList1.DeleteNode (Deletenode); Delete a node

}

4. Add a picture to a node

Treelistdevice.appendnode (new object[] {ID, type}, 0, 0, 0, 0); 0 for the first few pictures for the root directory, 1 for the child node picture

5. Add a background color to the node

private void Treelistconcentration_customdrawnodecell (object sender, Customdrawnodecelleventargs e) {String sql = " Select alarm information from real-time monitoring data where device number = ' "+ NodeID +" ' "; DataTable dt = datahelper.executedatatable (sql, Datahelper.databasetype. Attribute database); if (dt. Rows.Count > 0) {string co = ""; String worninfo = dt. rows[0]["alarm Information"]. ToString ();

String co = worninfo.substring (0, 1);//Carbon monoxide//string H2S = worninfo.substring (1, 1);//hydrogen sulfide//string Cl2 = Worninfo.substr ING (2, 1);//Recording gas//string O2 = worninfo.substring (3, 1);//oxygen//string HN3 = worninfo.substring (4, 1);//ammonia//string PID = wor Ninfo.substring (5, 1);//Photoelectric away from//string HCL = worninfo.substring (5, 1);//椂 hydrogen string CH4 = worninfo.substring (6, 1);//Methane if (E . NODE[1]! = null) {if (e.node[0]. ToString (). Trim () = = "Carbon monoxide (ppm)") {message = worninfo.substring (0, 1);//Carbon monoxide Cellbackcolor (e, message);} if (E.node[0]. ToString (). Trim () = = "Hydrogen sulfide (ppm)") {message = Worninfo.substring (1, 1);//hydrogen sulfide cellbackcolor (e, message);} if (E.node[0]. ToString (). Trim () = = "chlorine (ppm)") {message = Worninfo.substring (2, 1);//Air Cellbackcolor (e, message);} if (E.node[0]. ToString (). Trim () = = "Oxygen (VOL%)") {message = Worninfo.substring (3, 1);//Oxygen Cellbackcolor (E, message);} if (E.node[0]. ToString (). Trim () = = "ammonia (ppm)") {message = Worninfo.substring (4, 1);//Ammonia Cellbackcolor (e, message);//e.appearance.backcolor = Color.Red; } if (E.node[0]. ToString (). Trim () = = "Photoelectric Away (ppm)") {message = Worninfo.substring (5, 1);//Photoelectric away from Cellbackcolor (e, message);//e.appearance.backcolor = Col Or. Blue; } if (E.node[0]. ToString (). Trim () = = "Hydrogen chloride (ppm)") {message = Worninfo.substring (6, 1);//椂 hydrogen cellbackcolor (e, message);//e.appearance.backcolor = Col Or. Blue; } if (E.node[0]. ToString (). Trim () = = "Methane (lel%)") {message = Worninfo.substring (7, 1);//Methane Cellbackcolor (e, message);//e.appearance.backcolor = Colo R.blue; }

} }

}

Set multiple Colors

private void Cellbackcolor (Customdrawnodecelleventargs e, string message) {switch (message) {case "Z"://Sensor not open

E.appearance.backcolor = Color.yellow; Break Case "I"://Sensor communication interrupt E.appearance.backcolor = Color.Blue; Break Case "L"://Sensor error e.appearance.backcolor = Color.brown; Break Case "A"://Sensor threshold alarm E.appearance.backcolor = color.red; Break Default:e.appearance.backcolor = Color.Empty; Break } }

Data source Binding Treelist

Query device public static void Selectdevice (Treelist treedevice) {String sql = ' Select did,dname from DeviceMap '; DataTable dt= datahelper.executedatatable (SQL, Datahelper.databasetype. Attribute database); if (dt. rows.count>0) {for (int i = 0; i < dt. Rows.Count; i++) {String id = dt. Rows[i]["did"). ToString (); String type = dt. rows[i]["Dname"]. ToString (); Treedevice.appendnode (new object[] {id,type},-1); } } }

Treedevice.columns["did"). Caption = "category"; treedevice.columns["DType"]. Caption = "Alias";

Note: The field must be bound

Middle Insert Node

private void Treelist2_cellvaluechanged (object sender, DevExpress.XtraTreeList.CellValueChangedEventArgs e)// A cell already has a value that adds an empty message {string name = E.node.getdisplaytext (0), if (Name! = "") {Treelistnode Node = Treelist2.appendnode (New OB Ject[] {""},-1);

Treelist2.setnodeindex (node,e.node.id+1);

Treelist2.appendnode (new object[] {""},-1);}}

Get the selected node

NodeID = Convert.ToInt32 (TreeList1.FocusedNode.GetValue (TREELISTCOLUMN6));

Application of treelist in Dev (rpm)

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.