Forums
Forums are Read-Only. Use the new Support Center. To start a general discussion, use the General category when submitting your question.

DataLayoutControl - Custom Editors

Last post 9/16/2010 2:29 PM by Brendon Muck [DX Squad]. 3 replies.
Sort Posts: Previous Next
  • Oddo&Cie

    DataLayoutControl - Custom Editors

    5/20/2008 5:10 AM
    • Not Ranked
    • Joined on 7/2/2007
    • Posts 2

    Hi,

     

    I'm developping custom editors following this article : http://www.devexpress.com/Help/?document=XtraEditors/CustomDocument1291.htm

    It works great with Devexpress Datagrid. But not with DataLayoutControl.

    Is their any way to register these editors so the Datalayoutcontrol Databindings Wizard allow them to be selected?

     

    Thanks,

    Vincent

  • Oddo&Cie

    Re: DataLayoutControl - Custom Editors

    5/20/2008 3:27 PM
    • Not Ranked
    • Joined on 7/2/2007
    • Posts 2

    solution found by inheriting DataLayoutControl and the class below, praise the almighty reflector :) btw an easier solution would be appreciated... (too much private!) :

    public class ControlsManager
    
    Name:

    DevExpress.XtraDataLayout.ControlsManager

  • Mike Schuch_2

    Re: DataLayoutControl - Custom Editors

    9/8/2010 9:59 PM
    • Not Ranked
    • Joined on 10/31/2009
    • Posts 13

    So what did you figure out?

     

  • Brendon Muck [DX Squad]

    Re: DataLayoutControl - Custom Editors

    9/16/2010 2:29 PM
    • Top 10 Contributor
    • Joined on 5/16/2007
    • Buffalo, NY
    • Posts 6,154

    First, you need to create a class that inherits from the DevExpress.XtraDataLayout.ControlsManager class. Override the GetSuggestedControl method, and within this method, apply your logic to determine which control to use.

    Next, create a class that inherits from the DevExpress.XtraDataLayout.DataLayoutControl class. In this class, override the CreateControlsManager and return an instance of your ControlManager class.

    So if you have a basic custom control like:

     

        public class MyComboBoxEdit : DevExpress.XtraEditors.ComboBoxEdit

        {

            protected override void OnCreateControl()

            {

                Properties.Items.Add("a");

                Properties.Items.Add("b");

                Properties.Items.Add("c");

     

                base.OnCreateControl();

            }

        }

    You'll create a ControlsManager class, and maybe use that custom control as the default editor for strings:

     

        public class MyControlsManager : DevExpress.XtraDataLayout.ControlsManager

        {

            public override Type GetSuggestedControl(Type dataType)

            {

                if (dataType == typeof(string))

                {

                    return typeof(MyComboBoxEdit);

                }

                else

                {

                    return base.GetSuggestedControl(dataType);

                }

            }       

        }

     

    And finally, a DataLayoutControl descendant to encapsulate it all:

     

        public class MyDataLayoutControl : DevExpress.XtraDataLayout.DataLayoutControl

        {

            protected override DevExpress.XtraDataLayout.ControlsManager CreateControlsManager()

            {

                return new MyControlsManager();

            }

        }

     

    Create a form, drag your custom DataLayoutControl onto the form, set the data source, and you should see that any string property will automatically default to the "MyComboBoxEdit" type.

    Keep in mind I haven't fully tested or tried this out. I just saw the thread and this is what I came up with.

    Please do not email me directly for support. Use the Support Center or Community Forums so that everyone may benefit.
More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.