private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Node.Tag != null) { object settings = e.Node.Tag; propertyGrid1.SelectedObject = settings; _currentSetting = (XmlSettingsManager)propertyGrid1.SelectedObject; } }
private void InitTreeView() { treeView1.Select(); object setting; var root = new TreeNode("Settings"); treeView1.Nodes.Add(root); string appSettingsPath = Settings.Default.SettingsPath; string settingsCommentsPath = Settings.Default.SettingsCommentsPath; if (!Path.IsPathRooted(appSettingsPath)) { appSettingsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, appSettingsPath); } if (!Path.IsPathRooted(settingsCommentsPath)) { settingsCommentsPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, settingsCommentsPath); } _logger.Debug("will try to load service settings file: " + appSettingsPath); _logger.Debug("will try to load comments file: " + settingsCommentsPath); // here is the place you have to add your setting files setting = new XmlSettingsManager(typeof(General).FullName, appSettingsPath, settingsCommentsPath); root.Nodes.Add(new TreeNode("General Settings") { Tag = setting }); setting = new XmlSettingsManager(typeof(Advanced).FullName, appSettingsPath, settingsCommentsPath); root.Nodes.Add(new TreeNode("Advanced Settings") { Tag = setting }); //continue to add your settings categories here... // end of add settings files treeView1.ExpandAll(); treeView1.SelectedNode = root.FirstNode; treeView1_NodeMouseClick(this, new TreeNodeMouseClickEventArgs(root.FirstNode, MouseButtons.Right, 1, 0, 0)); }