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:C#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:C#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.C#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.C#void edit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { this.openFileDialog1.ShowDialog(); }
Files to Review
- File.cs (VB: File.vb)
- Form1.cs (VB: Form1.vb)
- FilteredFileNameEditor.cs (VB: FilteredFileNameEditor.vb)
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraVerticalGrid.Rows;
using System;
namespace T415077 {
public partial class Form1 : XtraForm {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
Data.File file = new Data.File() { Path = "C:\\Home", Path2 = "C:\\Public" };
this.propertyGridControl1.SelectedObject = file;
}
void edit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) {
this.openFileDialog1.ShowDialog();
}
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;
}
}
}
C#using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
namespace T415077.UIEditors {
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);
}
}
}