首页 > 其他分享 >操作Devexpress treelist中的项

操作Devexpress treelist中的项

时间:2022-12-05 12:34:37浏览次数:61  
标签:Node string Devexpress Substring wornInfo ToString treelist 操作 message


如果需要在单元格添加时则用TreeList如果只是单纯读取数据或检索数据时则用GridControl

操作Devexpress treelist中的项_string

1.如果点击添加 时则添加TreeList的节点:

protected internal void btnAdd_Click(object sender, EventArgs e)
{
if (treeList1.Nodes.Count == 0)
{
TreeListNode node = treeList1.AppendNode(new object[] { 0}, -1); //数组中可写多个参数,但是每一个参数代表一列
}
else
{
int dy = Convert.ToInt32(treeList1.Nodes.LastNode.GetValue("cID")); //获取最后一节点ID
TreeListNode node = treeList1.AppendNode(new object[] { dy + 1 }, -1);


           

      

2.  cPort = treeList1.Nodes[i].GetDisplayText("cPort").ToString().Trim(); //获取单元格中的文本,cport代表列名

bool falge = Convert.ToBoolean(treeList1.Nodes[i].GetValue("cFlage")); //获取复选框的值,cFlage则代表列名

3.删除选中的节点

/// <summary>
/// 最后选择的节点
/// </summary>
private void treeList1_AfterFocusNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
{

public void btnDel_Click(object sender, EventArgs e)

}


4.给节点添加图片

 


5.给节点添加背景颜色

private void treeListConcentration_CustomDrawNodeCell(object sender, CustomDrawNodeCellEventArgs e)
{
string sql = "select 报警信息 from 实时监测数据 where 设备编号='" + nodeID + "'";
DataTable dt = DataHelper.ExecuteDataTable(sql, DataHelper.DataBaseType.属性数据库);
if (dt.Rows.Count > 0)
{
string co = "";
//string co = wornInfo.Substring(0, 1);//一氧化碳
//string h2s = wornInfo.Substring(1, 1);//硫化氢
//string cl2 = wornInfo.Substring(2, 1);//录气
//string O2 = wornInfo.Substring(3, 1);//氧气
//string hn3 = wornInfo.Substring(4, 1);//氨气
//string pid = wornInfo.Substring(5, 1);//光电离
//string hcl = wornInfo.Substring(5, 1);//椂化氢
string ch4 = wornInfo.Substring(6, 1);//甲烷
if (e.Node[1] != null)
{
if (e.Node[0].ToString().Trim() == "一氧化碳(ppm)")
{
message = wornInfo.Substring(0, 1);//一氧化碳
CellBackColor(e, message);
}
if (e.Node[0].ToString().Trim() == "硫化氢(ppm)")
{
message = wornInfo.Substring(1, 1);//硫化氢
CellBackColor(e, message);
}
if (e.Node[0].ToString().Trim() == "氯气(ppm)")
{
message = wornInfo.Substring(2, 1);//录气
CellBackColor(e, message);
}
if (e.Node[0].ToString().Trim() == "氧气(VOL%)")
{
message = wornInfo.Substring(3, 1);//氧气
CellBackColor(e, message);
}
if (e.Node[0].ToString().Trim() == "氨气(ppm)")
{
message = wornInfo.Substring(4, 1);//氨气
CellBackColor(e, message);
//e.Appearance.BackColor = Color.Red;
}
if (e.Node[0].ToString().Trim() == "光电离(ppm)")
{
message = wornInfo.Substring(5, 1);//光电离
CellBackColor(e, message);
//e.Appearance.BackColor = Color.Blue;
}
if (e.Node[0].ToString().Trim() == "氯化氢(ppm)")
{
message = wornInfo.Substring(6, 1);//椂化氢
CellBackColor(e, message);
//e.Appearance.BackColor = Color.Blue;
}
if (e.Node[0].ToString().Trim() == "甲烷(LEL%)")
{
message = wornInfo.Substring(7, 1);//甲烷
CellBackColor(e, message);
//e.Appearance.BackColor = Color.Blue;
}

//设置多个颜色

private void CellBackColor(CustomDrawNodeCellEventArgs e, string message)
{
switch (message)
{
e.Appearance.BackColor = Color.Yellow;
break;
case "I"://传感器通信中断
e.Appearance.BackColor = Color.Blue;
break;
case "L"://传感器错误
e.Appearance.BackColor = Color.Brown;
break;
case "A"://传感器阈值报警
e.Appearance.BackColor = Color.Red;
break;
default:
e.Appearance.BackColor = Color.Empty;
break;
}

数据源绑定TreeList

//查询设备
public static void selectDevice(TreeList treeDevice)
{
string sql = "select dID,dName from DeviceMap ";
DataTable dt= DataHelper.ExecuteDataTable(sql, DataHelper.DataBaseType.属性数据库);
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 = "类别";


               

注意:必须得绑定字段


//中间插入节点
private void treeList2_CellValueChanged(object sender, DevExpress.XtraTreeList.CellValueChangedEventArgs e)//单元已有值就会增添一条空信息
{
string name = e.Node.GetDisplayText(0);
if (name != "")
{
TreeListNode node =
//treeList2.AppendNode(new object[] { "" }, -1);
}


       

获得选中的节点

  

标签:Node,string,Devexpress,Substring,wornInfo,ToString,treelist,操作,message
From: https://blog.51cto.com/u_11295556/5911886

相关文章

  • DevExpress控件之
    1、OptionsSelection:EnableAppearanceForcusedCell:选中的Cell的Appearance设置是否可用。默认为True;......
  • Python 操作 Excel
    Python操作Excel目录Python操作Excel1安装pandas2pandas中操作Excel的函数2.1loc()2.1.1根据某些条件选择数据2.1.2选择一个行的范围2.1.3根据条件更新列的值......
  • Selenium4+Python3系列(九) - 上传文件及滚动条操作
    一、上传文件操作上传文件是每个做自动化测试同学都会遇到,而且可以说是面试必考的问题,标准控件我们一般用​​send_keys()​​​就能完成上传,但是我们的测试网站的上传控件......
  • Wps调用dll操作Excel表格转PDF
     起始原因:wps编辑创建的文档在microsoftoffice中打开,会报内容存在异常是否恢复,因此wps文件被微软设定为破损文件,无法对原有文档进行操作运行,故在此使用wps对Excel进行......
  • MySQL记录用户操作日志
    MySQL记录用户操作日志有时,我们想追踪某个数据库操作记录,如想找出是谁操作了某个表(比如谁将字段名改了)。二进制日志记录了操作记录,线程号等信息,但是却没有记录用户信息,因此......
  • Navicat中MySQL命令列界面操作及基础常用命令
    https://blog.csdn.net/weixin_71712767/article/details/126863842如何使用navicat进入MySQL命令行界面?如何通过命令对数据库/表进行操作? 如何在Navicat中MySQL链接打......
  • 二叉树基本操作代码实现
    #include<stdio.h>#include<stdlib.h>//exit#include<malloc.h>//定义二叉链表结点结构typedefstructnode{ intdata; structnode*lchild,*rchild;}BiTr......
  • SQL操作全集
    下列语句部分是Mssql语句,不可以在access中使用。SQL分类:DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)DCL—数据控制语......
  • 导入hellodb.sql生成数据库 ,完成下列操作
    导入hellodb.sql生成数据库,完成下列操作目录导入hellodb.sql生成数据库,完成下列操作导入hellodb.sql查询1.在students表中,查询年龄大于25岁,且为男性的同学的名字和年龄......
  • Stream流处理介绍以及Stream的基本操作
    Stream(流)是一个来自数据源的元素队列,元素是特定类型的对象,形成一个队列。Java中的Stream并不会存储元素,而是按需计算。数据源:流的来源,可以是集合,数组等。和以前的Collec......