代码如下
public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            try
            {
                _db = Decoder.Config.ConfigData.Instance();
            }
            catch(Exception)
            {
                MessageBox.Show(@"Can not open config database");
                Close();
                return;
            }
            CreatTree();
        }
        
        private  Decoder.Config.ConfigData _db;
        private void CreatTree()
        {
            string sql = @"select classificationid,classificationname from MetricClassification";
            DataSet ds = _db.ExecuteDataset(sql);            foreach (DataRow row in ds.Tables[0].Rows)
            {
                TreeNode tn = tv.Nodes.Add(row["classificationid"].ToString(), row["classificationname"].ToString());                CreatChildTree(tn, row["classificationid"].ToString());
            }
        }        private void CreatChildTree(TreeNode tn ,string parentid)
        {
            string sql = @"select metricid,metricname from Metric where metricid=" + parentid;
            DataSet ds = _db.ExecuteDataset(sql);            foreach (DataRow row in ds.Tables[0].Rows)
            {
                tn.Nodes.Add(row["metricid"].ToString(), row["metricname"].ToString());
            }
        }        public  static string NodeName = string.Empty;        private void tv_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            //获取单击节点的名字
            TreeNode treeNode = sender as TreeNode;
            NodeName = treeNode.Name;
        }        private void tv_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            //通过双击节点获取节点的名字
            TreeNode treeNode = sender as TreeNode;
            string name = treeNode.Name;
            RightClick(name);
        }        private void Btright1Click(object sender, EventArgs e)
        {
            listView1.Clear();
            RightClick(NodeName);
        }        private void RightClick(string name)
        {
            string sql = @"select metricid from metric where metricname={0}";
            name = string.Empty;
            string sqlstring = string.Format(sql, name);
            string id = string.Empty;
            DataRow row = _db.ExecuteDataset(sqlstring).Tables[0].Rows[0];
            id = row[0].ToString();//通过获取的节点名字找到它对应的ID            string sqlmetricthreshold = @"select name from metricthreshold where metricid={0}";
            string sqlstrings = string.Format(sqlmetricthreshold, id);
            DataRow dataRow  = _db.ExecuteDataset(sqlstrings).Tables[0].Rows[0];
            var Namen = dataRow[0].ToString();//通过表1表2之间对应的ID值,找到表2中的Namen
            
            if (tv.SelectedNode == null)
                return;            listView1.Items.Add(Namen);           
        }
    }access数据库表是自己随便定义的几个表跟信息内容