This example demonstrates how to implement a UI Type Editor (FilteredFileNameEditor
) and use it within the PropertyGridControl.
-
Create a
FilteredFileNameEditor
class and implement the UITypeEditor interface:internal class FilteredFileNameEditor : UITypeEditor { private OpenFileDialog ofd = new OpenFileDialog(); public override UITypeEditorEditStyle GetEditStyle( ITypeDescriptorContext context) { return UITypeEditorEditStyle.Modal; } public override object EditValue( ITypeDescriptorContext context, IServiceProvider provider, object value) { ofd.FileName = value.ToString(); ofd.Filter = "Text File|*.txt|All Files|*.*"; if (ofd.ShowDialog() == DialogResult.OK) { return ofd.FileName; } return base.EditValue(context, provider, value); } }
-
Apply the
System.ComponentModel.Editor
attribute as follows:public class File { [System.ComponentModel.Editor(typeof(UIEditors.FilteredFileNameEditor), typeof(System.Drawing.Design.UITypeEditor))] public string Path { get; set; } public string Path2 { get; set; } }
-
Assign a
ButtonEdit
to a cell as shown in the Assigning Editors to Editor Rows topic.private void Form1_Shown(object sender, EventArgs e) { RepositoryItemButtonEdit edit = new RepositoryItemButtonEdit(); edit.ButtonClick += edit_ButtonClick; (this.propertyGridControl1.Rows[0] as CategoryRow).ChildRows["rowPath2"].Properties.RowEdit = edit; }
-
Handle the Button Editor's
ButtonClick
event.void edit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { this.openFileDialog1.ShowDialog(); }
- File.cs (VB: File.vb)
- Form1.cs (VB: Form1.vb)
- FilteredFileNameEditor.cs (VB: FilteredFileNameEditor.vb)
(you will be redirected to DevExpress.com to submit your response)