ComboBox items are not displayed in drop down list

ComboBox items are not displayed in drop down list when class is delivered from from UserControl.
Help fix this.. I need class type UserControl.
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        Uc f = new Uc();
        comboBox1.Items.Add(f);
        comboBox1.Items.Add("Upper item is empty why?");
    }
}

public class Uc : UserControl
{
    public override string ToString()
    {
        return "not visible text";
    }
}

Open in new window

LVL 6
CebikAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HainKurtSr. System AnalystCommented:
try adding public properties...

Uc f = new Uc();
f.Name = "HainKurt";
f.Value = "HK";
comboBox1.Items.Add(f);

or try these

// comboBox1.Items.Add(f.Name);
// comboBox1.Items.Add(f.Value);
// comboBox1.Items.Add(f.toString());
private String _Name;
public String Name {
  get { return _Name;}
  set { _Name = value; }
}

private String _Value;
public String Value {
  get { return _Value;}
  set { _Value = value; }
}

Open in new window

0
CebikAuthor Commented:
I prefer to add an object. This isn't helping. The same result.
0
tikusbalapCommented:
Why deriving from UserControl?
0
CebikAuthor Commented:
The truth is that it is UserControl and I want to have it in combobox.
0
CebikAuthor Commented:
I've found a solution by my self..
(property in class and displaymember in combobox)
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        uc f = new uc();

        comboBox1.DisplayMember = "DisplayText"; 
        comboBox1.Items.Add(f);
        
    }
}

public class uc : UserControl
{
    string text = "example";

    public override string ToString()
    {
        return text;    //not working
    }

    public String DisplayText
    {
        get { return text; }
    }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.