public override object EditValue(ITypeDescriptorContext context, System.IServiceProvider provider, object value) { if (context == null || provider == null || context.Instance == null) { return base.EditValue(provider, value); } ShellBrowseForFolderDialog folderDialog = new ShellBrowseForFolderDialog(); try { folderDialog.hwndOwner = System.Windows.Forms.Form.ActiveForm.Handle; } catch{} _InitialFolder=(string)value; FolderDialogTitleAttribute titleAtt = (FolderDialogTitleAttribute)context.PropertyDescriptor.Attributes[typeof(FolderDialogTitleAttribute)]; if (titleAtt != null) { folderDialog.Title = titleAtt.Title; } folderDialog.OnInitialized += new ShellBrowseForFolderDialog.InitializedHandler(this.InitializedEvent); if (folderDialog.ShowDialog() == DialogResult.OK) { value = folderDialog.FullName; } return value; }
private void InitializedEvent(ShellBrowseForFolderDialog sender, ShellBrowseForFolderDialog.InitializedEventArgs args) { sender.SetSelection(args.hwnd, _InitialFolder); }
private void btnAdd_Click(object sender, System.EventArgs e) { string path = null; ShellBrowseForFolderDialog folderDialog = new ShellBrowseForFolderDialog(); folderDialog.hwndOwner = this.Handle; if (folderDialog.ShowDialog() == DialogResult.OK) { path = folderDialog.FullName; foreach (ListViewItem sel_li in listView1.SelectedItems) { sel_li.Selected = false; } ReferencePath rp = new ReferencePath(); rp.Path = path; ListViewItem li = new ListViewItem(); listView1.Items.Add(li); li.Tag = rp; UpdateListItem(li); _refPaths.Add(rp); li.Selected = true; } }