How to create a derived ComboBox with a pre-bound data source that is designer friendly?

I would like to create a derived control from System.Windows.Forms.ComboBox, which is tied to a list of objects that I retrieve from the database. Other developers' ideas may simply discard this control in their form, without worrying about the data source, binding if they don't want to.

I tried extending combobox and then setting the constructor for DataSource, DisplayMember and ValueMember in the constructor.

public class CustomComboBox : ComboBox
{
    public CustomComboBox() 
    {
        this.DataSource = MyDAL.GetItems(); // Returns List<MyItem>
        this.DisplayMember = "Name";
        this.ValueMember = "ItemID";
    }
}

Works when I run, but throws a lot of errors in Visual Studio after adding to any form. The error I am getting is:

" " " . :" ​​ "

(#, Winforms,.NET 2.0+)?

+3
3

DesignMode . LicenseManager.

if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
{
    // Do your database/IO/remote call
}

LicenseManager . DesignMode.

: http://dotnetfacts.blogspot.com/2009/01/identifying-run-time-and-design-mode.html

: http://weblogs.asp.net/fmarguerie/archive/2005/03/23/395658.aspx

+2

, , .

:

if (!DesignMode)
{
  //Do this stuff
}

- .

+6

- DesignMode , - , , DesignMode , . , , . , (, Common Dialog).

See http://keyofdflat.livejournal.com/5407.html (be sure to read the last comment).

0
source

All Articles