private void ToolBars_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
        {
            if (AddProfile.Equals(e.Button))
            {
                profilesTreeView = new ProfilesTreeView(context);
                profilesTreeView.LoadProfiles();

                var dialogResult = profilesTreeView.ShowDialog(this);

                if (dialogResult == DialogResult.OK)
                {
                    profilesModels.AddRange(profilesTreeView.SelectedTreeViewNodes.Where(item => !profilesModels.Contains(item)));

                    ProfilesListBox.DataSource    = profilesModels;
                    ProfilesListBox.DisplayMember = "Name";
                    ProfilesListBox.ValueMember   = "NodeProfileSession";

                    profilesTreeView.Dispose();
                }
            }
            else if (RemoveProfile.Equals(e.Button))
            {
                foreach (var item in ProfilesListBox.SelectedItems)
                {
                    profilesModels.Remove(item as Models.TreeViewNodeModel);
                }
                //TODO: Remove SPIKE with DataBindings reassigning
                ProfilesListBox.DataSource    = null;
                ProfilesListBox.DataSource    = profilesModels;
                ProfilesListBox.DisplayMember = "Name";
                ProfilesListBox.ValueMember   = "NodeProfileSession";
            }
        }
Exemple #2
0
        private void ToolBars_ButtonClick(object sender, ToolBarButtonClickEventArgs e)
        {
            if (AddProfile.Equals(e.Button))
            {
                profilesTreeView = new ProfilesTreeView(context);
                profilesTreeView.LoadProfiles();

                var dialogResult = profilesTreeView.ShowDialog(this);

                if (dialogResult == DialogResult.OK)
                {
                    var profiles = profilesTreeView.SelectedTreeViewNodes.Where(item => !profilesModels.Any(model => item.NodeProfileSession.SessionId == model.NodeProfileSession.SessionId));

                    foreach (var profile in profiles)
                    {
                        profilesModels.Add(profile);
                    }

                    ProfilesListBox.DataSource    = profilesModels;
                    ProfilesListBox.DisplayMember = "Name";
                    ProfilesListBox.ValueMember   = "NodeProfileSession";

                    profilesTreeView.Dispose();
                }
            }
            else if (RemoveProfile.Equals(e.Button))
            {
                var selectedItems = new List <TreeViewNodeModel>();

                for (int i = 0; i < ProfilesListBox.SelectedItems.Count; i++)
                {
                    selectedItems.Add(ProfilesListBox.SelectedItems[i] as TreeViewNodeModel);
                }

                foreach (var item in selectedItems)
                {
                    profilesModels.Remove(item);
                }

                //TODO: Remove SPIKE with DataBindings reassigning
                ProfilesListBox.DataSource    = null;
                ProfilesListBox.DataSource    = profilesModels;
                ProfilesListBox.DisplayMember = "Name";
                ProfilesListBox.ValueMember   = "NodeProfileSession";
            }
        }