Multiline PropertyGridTextBoxEditor

6 posts, 0 answers
  1. Chris Gethin
    Chris Gethin avatar
    4 posts
    Member since:
    Mar 2010

    Posted 24 May 2012 Link to this post

    Hi,

    Is it possible to set a PropertyGridTextBoxEditor to be multiline?

    I have tried the following approach, but although the Multiline property does successfully get set to true, the textbox does not display as such.

     

     

    private void detailsPropertyGrid_EditorInitialized(object sender, PropertyGridItemEditorInitializedEventArgs e)
            {
                switch (e.Item.Name)
                {
                    case "Details":
                        PropertyGridTextBoxEditor editor = e.Editor as PropertyGridTextBoxEditor;
                        editor.Multiline = true;
                        break;
                    default:
                        return;
                }
            }

    Thanks,

    Chris.

  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 29 May 2012 Link to this post

    Hello Chris,

    Thank you for writing.

    The RadPropertyGrid items have a fixed size and they cannot be resized to take a multiline text box. You can create a custom editor to show a bigger element containing a multiline text box. You can read more on creating a custom editor in out online documentation.

    I hope this will be useful. If you have further questions, I would be glad to help.

    All the best,
    Ivan Petrov
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  3. Andreas
    Andreas avatar
    4 posts
    Member since:
    Oct 2017

    Posted 28 Dec 2017 in reply to Ivan Petrov Link to this post

    Is there still no other possibility to create Multiline Textbox?
  4. Dess
    Admin
    Dess avatar
    2772 posts

    Posted 29 Dec 2017 Link to this post

    Hello, Andreas, 

    Thank you for writing.  

    In order to enable multiline PropertyGridTextBoxEditor you can refer to the following code snippet:
    public RadForm1()
    {
        InitializeComponent();
        this.radPropertyGrid1.SelectedObject = new Item(123, "First row" + Environment.NewLine + "Second row",DateTime.Now );
        this.radPropertyGrid1.EditorInitialized+=radPropertyGrid1_EditorInitialized;
        this.radPropertyGrid1.ItemHeight = 50;
    }
     
    private void radPropertyGrid1_EditorInitialized(object sender, Telerik.WinControls.UI.PropertyGridItemEditorInitializedEventArgs e)
    {
        PropertyGridTextBoxEditor editor = e.Editor as PropertyGridTextBoxEditor;
        if (editor!=null)
        {
            editor.Multiline = true;
        }
    }
     
    public class Item
    {
        public int Id { get; set; }
     
        public string Name { get; set; }
     
        public DateTime CreatedOn { get; set; }
     
        public Item(int id, string name, DateTime createdOn)
        {
            this.Id = id;
            this.Name = name;
            this.CreatedOn = createdOn;
        }
    }



    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Andreas
    Andreas avatar
    4 posts
    Member since:
    Oct 2017

    Posted 04 Jan in reply to Dess Link to this post

    works fine. But how can I add more than 1 Multiline Item to property grid?

    Is it possible to add lines by List for example?

  6. Dess
    Admin
    Dess avatar
    2772 posts

    Posted 04 Jan Link to this post

    Hello, Andreas, 

    Thank you for writing.  

    Each property of the RadPropertyGrid.SelectedObject is displayed as a PropertyGridItem. You can add as many string properties as you wish that contain multiline data. However, if you have a property of type List<string> and want to display it as multiline text and edit this text, you can use a custom TypeConverter. I have prepared a sample code snippet which result is illustrated in the attached gif file: 
    public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent();
            this.radPropertyGrid1.SelectedObject = new Item(123, "First row" + Environment.NewLine + "Second row",DateTime.Now);
            this.radPropertyGrid1.EditorInitialized += radPropertyGrid1_EditorInitialized;
            this.radPropertyGrid1.ItemHeight = 50;
        }
     
        private void radPropertyGrid1_EditorInitialized(object sender, Telerik.WinControls.UI.PropertyGridItemEditorInitializedEventArgs e)
        {
            PropertyGridTextBoxEditor editor = e.Editor as PropertyGridTextBoxEditor;
            if (editor != null)
            {
                editor.Multiline = true;
            }
        }
     
        public class Item
        {
            public int Id { get; set; }
     
            public string Name { get; set; }
     
            public DateTime CreatedOn { get; set; }
             
            [Editor(typeof(PropertyGridTextBoxEditor), typeof(BaseInputEditor))]
            [TypeConverter(typeof(MyTypeConverter))]
            public List<string> TextItems { get; set; }
     
            public Item(int id, string name, DateTime createdOn)
            {
                this.Id = id;
                this.Name = name;
                this.CreatedOn = createdOn;
                this.TextItems = new List<string>() { "one", "two", "three" };
            }
        }
     
        public class MyTypeConverter:TypeConverter
        {
            public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
            {
                if (destinationType == typeof(string))
                {
                    return true;
                }
                return base.CanConvertTo(context, destinationType);
            }
     
            public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
            {
                if (destinationType == typeof(string))
                {
                    List<string> textItems = value as List<string>;
                    if (textItems != null)
                    {
                        return String.Join(Environment.NewLine, textItems);
                    }
                    return true;
                }
                return base.ConvertTo(context, culture, value, destinationType);
            }
     
            public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
            {
                if (sourceType == typeof(string))
                {
                    return true;
                }
                return base.CanConvertFrom(context, sourceType);
            }
     
            public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
            {
                if (value == null)
                {
                    return new List<string>();
                }
                string text = value.ToString();
                string[] tokens = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                return tokens.ToList();
            }
        }
    }

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top