Skip to content

DevExpress-Examples/winforms-property-grid-create-custom-editor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WinForms Property Grid - Use a custom cell editor

This example demonstrates how to implement a UI Type Editor (FilteredFileNameEditor) and use it within the PropertyGridControl.

  1. 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);
        }
    }
  2. 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; }
    }
  3. 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;
    }
  4. Handle the Button Editor's ButtonClick event.

    void edit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) {
        this.openFileDialog1.ShowDialog();
    }

Files to Review

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Contributors 2

  •  
  •  
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy