操作Devexpress treelist中的项

 

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

dev中TreeList的应用

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>
        TreeListNode deletenode;

        private void treeList1_AfterFocusNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
        {
            deletenode =e.Node; //获取最后的ID

        }

public void btnDel_Click(object sender, EventArgs e)
        {

            this.treeList1.DeleteNode(deletenode); //删除节点

        }

 

4.给节点添加图片

   treeListDevice.AppendNode(new object[] { id, type }, 0, 0, 0, 0); //0代表第几张图片代表根目录用的,-1代表子节点图片

 

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 wornInfo = dt.Rows[0]["报警信息"].ToString();

                //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);
                    }

阅读更多
版权声明:大道至简,悟在天成。本文为博主原创文章,未经博主允许不得转载。http://blog.csdn.net/fwj380891124 https://blog.csdn.net/fwj380891124/article/details/6886069
个人分类: 技术交流
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭