从数据库中读取数据动态添加到contextmenu指定的位置,当我数据库中数据发生变化的时候,如何修改contextmenu呀?
用什么方法么?
主要是添加和删除数据库中数据的时候
下面函数主要实现了,动态添加数据到contextmenu和treeView
由于contextmenu中有不需要更新的数据,所以更新数据时候必须指定位置
 private void refreshMenuItemAndTree()
        {
            stationInfo = linkAccess.GetDBTableFromUser(string.Format("SELECT * FROM Cg_Station"));
            int count = stationInfo.Rows.Count;            if (count > 0)
            {
                int i = 2;
                foreach (DataRow dr in stationInfo.Rows)
                {
                    string tempStaName = dr[1].ToString();                    ToolStripMenuItem itm = new ToolStripMenuItem(tempStaName);
                    cnMStripForLoad.Items.Insert(i, itm);                    i = i + 1;                    itm.Click += new EventHandler(itm_Click);                    if (Convert.ToInt32(dr[0]) == defaultStation)
                    {
                        itm.Checked = true;
                        curFileName = dr[2].ToString();
                        curStaName = dr[1].ToString();
                        GlobalMembers.StaFileName = curFileName;
                    }                    TreeNode node = new TreeNode();
                    node.Name = dr[0].ToString();
                    node.Text = dr[1].ToString();
                    node.ForeColor = Color.Red;                    if (Convert.ToInt32(node.Name) == defaultStation)
                    {
                        node.Checked = true;
                    }
                    treeViewForStation.Nodes.Add(node);                }
            }
        }现在的问题是,我在更新了数据库后,如何更新contextmenu呢?
添加了数据的话,需要contextmenu保留原来数据的基础上,继续在指定位置添加新的数据
删除了数据的话,需要contextmenu删除指定的数据