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.