Пример #1
0
        private void UpdateTreeView()
        {
            try
            {
                Messages_TreeView.Nodes.Clear();
                TreeNode root = new TreeNode("Messages", rootimageindex, rootimageindex);

                //Add The message Leaf here
                TreeNode[] msgs = MessageInfo.
                                  Select(x => new TreeNode
                {
                    Name = x.Key.ToString(),
                    //Text = x.Key.ToString(),
                    Text = GetFldValue(x.Key, x.Value[0]).ToString(),
                    SelectedImageIndex = SelectedMsgImageIndex,
                    ImageIndex         = UnSelectedMsgImageIndex
                })
                                  .ToArray <TreeNode>();

                foreach (var message in MessageInfo)
                {
                    msgs[message.Key].Nodes.AddRange(MessageInfo[message.Key].Where(y => y.Key > 0)
                                                     .Select(x => new TreeNode
                    {
                        Name = x.Key.ToString(),
                        Text = GetFldValue(x.Key, x.Value).ToString(),
                        SelectedImageIndex = SelectedFldImageIndex,
                        ImageIndex         = UnSelectedFldImageIndex
                    })
                                                     .ToArray <TreeNode>());
                }
                Messages_TreeView.Nodes.Add(root);
                root.Nodes.AddRange(msgs);
                Messages_TreeView.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #2
0
        private void addFieldToolStripBelowMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (Messages_TreeView.SelectedNode != null)
                {
                    List <KeyValue> fcopy = FieldProperty.Fieldlist.Select(o => new KeyValue
                    {
                        Key       = o.Key,
                        ValueType = o.ValueType,
                        Value     = o.Value
                    }).ToList();

                    switch (Messages_TreeView.SelectedNode.Level)
                    {
                    case 1:
                    {
                        switch (Messages_TreeView.SelectedNode.Index)
                        {
                        case 0:
                        default:
                            int selectedMsgindex = Messages_TreeView.SelectedNode.Index;
                            //if (MessageInfo[selectedMsgindex].ContainsKey(1))
                            {
                                var tempdict = MessageInfo[selectedMsgindex].Where(x => x.Key > 0).ToDictionary(p => p.Key + 1);
                                MessageInfo[selectedMsgindex].Remove(1);
                                MessageInfo[selectedMsgindex].Add(1, fcopy);
                                foreach (var ele in tempdict)
                                {
                                    MessageInfo[selectedMsgindex].Remove(ele.Key);
                                    MessageInfo[selectedMsgindex].Add(ele.Key, ele.Value.Value);
                                }
                            }
                            break;
                        }
                    }
                    break;

                    case 2:
                    {
                        int ParentNodeindex      = Messages_TreeView.SelectedNode.Parent.Index;
                        int SelectedfldNodeindex = Messages_TreeView.SelectedNode.Index;
                        ++SelectedfldNodeindex;
                        if (MessageInfo[ParentNodeindex].ContainsKey(SelectedfldNodeindex + 1))
                        {
                            var tempdict = MessageInfo[ParentNodeindex].Where(x => x.Key > SelectedfldNodeindex).ToDictionary(p => p.Key + 1);
                            MessageInfo[ParentNodeindex].Remove(SelectedfldNodeindex + 1);
                            MessageInfo[ParentNodeindex].Add(SelectedfldNodeindex + 1, fcopy);
                            foreach (var ele in tempdict)
                            {
                                MessageInfo[ParentNodeindex].Remove(ele.Key);
                                MessageInfo[ParentNodeindex].Add(ele.Key, ele.Value.Value);
                            }
                        }
                        else
                        {
                            int LastMessageKey = MessageInfo[ParentNodeindex].Keys.Last();
                            MessageInfo[ParentNodeindex].Add(LastMessageKey + 1, fcopy);
                        }
                    }
                    break;
                    }

                    UpdateTreeView();
                    Messages_TreeView.ExpandAll();
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }