title: Custom Combobox control custom datasource with custom displaymember and valuemember
body: <p>I'm developing a custom combobox control that inherits from another combobox (Janus UICombobox).
  I'd like the datasource to be based on a EntityType (LLBLGEN) so that when a user selects a EntityType all the database records for that EntityType will be loaded in the combobox.</p>
  
  <p>This is going fine when I build and run, but I would also like to be able to give the user the apportunity to select the DisplayMember and ValueMember based on the selected EntityType.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>    public partial class DtUiComboBox : UIComboBox
  {
      private Thread _loadThread;
  
      public DtUiComboBox()
      {
          InitializeComponent();
      }
  
      //Don't want this to be visible in the designer
      [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
      public new object DataSource
      {
          get;
          set;
      }
      //Don't want this to be visible in the designer
      [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
      public new string DisplayMember
      {
          get;
          set;
      }
      //Don't want this to be visible in the designer
      [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
      public new string ValueMember
      {
          get;
          set;
      }
      //Don't want this to be visible in the designer
      [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
      public new string DataMember
      {
          get;
          set;
      }
  
      //My Custom DisplayMember that should be based on the EntityFields from the selected EntityType
      [Category("Data")]
      public string DisplayField
      {
          get;
          set;
      }
      //My Custom ValueMember that should be based on the EntityFields from the selected EntityType
      [Category("Data")]
      public string ValueField
      {
          get;
          set;
      }
  
      private EntityType? _entityType;
      [Category("Data")]
      public EntityType? EntityTypeSource
      {
          get
          {
              return _entityType;
          }
          set
          {
              if (value != null)
              {
                  _entityType = value;
                  IEntity2 entity2 = Dal.FactoryClasses.GeneralEntityFactory.Create(_entityType.Value);
                  if (!DesignMode &amp;&amp; !IsDesignerHost)
                  {
                      if (_loadThread != null &amp;&amp; _loadThread.IsAlive)
                      {
                          _loadThread.Abort();
                          _loadThread.Join(500);
                      }
                      _loadThread = new Thread(new ThreadStart(LoadFromEntityType));
                      _loadThread.Start();
                  }
                  Invalidate(true);
              }
          }
      }
  
      private void LoadFromEntityType()
      {
          if (_entityType.HasValue)
          {
              IEntityCollection2 entityCollection = DtBlClient.Instance.Bl.GetCollection(_entityType.Value);
              LoadFromEntityType(entityCollection);
          }
      }
  
      private delegate void LoadFromEntityTypeDel(IEntityCollection2 collection2);
      private void LoadFromEntityType(object data)
      {
          if (this.InvokeRequired)
          {
              this.BeginInvoke(new LoadFromEntityTypeDel(LoadFromEntityType), data);
              return;
          }
          DataSource = data;
      }
  
      [BrowsableAttribute(false)]
      [Description("This method checks if I run in DesignMode, because Threading doesn't work in the Designer")]
      public bool IsDesignerHost
      {
          get
          {
              Control ctrl = this;
  
              while (ctrl != null)
              {
                  if ((ctrl.Site != null) &amp;&amp; ctrl.Site.DesignMode)
                      return true;
                  ctrl = ctrl.Parent;
              }
              return false;
          }
      }
  
      [Browsable(false)]
      [Description("This method checks if I run in DesignMode, because Threading doesn't work in the Designer")]
      public new static bool DesignMode
      {
          get
          {
              string processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
              if (processName.Equals("devenv"))
                  return true;
              return false;
          }
      }
  }
  </code></pre>
  
  <p>How can I do this ?</p>