0

I just want my ComboBox to show me the

FullName of objects in List(Curator),

but it show me the same "object.FullName" multiple times :-(

-

Basically, it work cause it show me the FullName of ONE of the Curator,

and the good amount of times,

but it show me the same ONE !

public partial class SGIArt : Form
{
     public static Gallery gal = new Gallery(); // from a dll i made

     List<Curator> curList = new List<Curator>();

     public SGIArt()
     {
        InitializeComponent();
        comboCur.DataSource = curList;
        comboCur.ValueMember = null;
        comboCur.DisplayMember = "FullName";
        UpdateCurList();
    }
    public void UpdateCurList()
    {
        curList.Clear();
        foreach (Curator cur in gal.GetCurList())    
                  // from the same dll : Curators curatorsList = new Curators();
        {
            curList.Add(cur);
        }
    }
    private void comboCur_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (comboCur.SelectedValue != null)
        {
            //show info in textBox (that work fine)
        }
    }
}

Curator class :

public class Curator : Person
{

    private int id;
    private double commission;
    const double commRate = 0.25;
    private int assignedArtists = 0;

    public int CuratorID
    {
        get
        {
            return id;
        }
        set
        {
            id = value;
        }
    }
    ...

    public Curator()
    {
    }

    public Curator(string First, string Last, int curID)
        : base(First, Last) // from : public abstract class Person
    {
        id = curID;
        commission = 0;
        assignedArtists = 0;
    }
MHX
  • 21
  • 3

2 Answers2

0

Edit: You might be looking for this answer.

I do not see the FullName member in your code snippet. I think you are looking for something like this:

List<Curator> curList = new List<Curator>();

public SGIArt()
{
  InitializeComponent();
  comboCur.DataSource = datasource;
  comboCur.ValueMember = null;
  comboCur.DisplayMember = "FullName";
  UpdateCurList();
}
List<string> datasource()
{
  List<string> datasource = new List<string>();
  foreach(Curator curator in  curList)
  {
    datasource.Add(curator.FullName)//this assume FullName is an accesible member of the Curator class and is a string.
  }
  return datasource;
}
Community
  • 1
  • 1
0

The comboBox shows you object.FullName, because this is what you are telling it. The curList is empty at the time when you bind it.

You can update your list before using it:

public SGIArt()
{
    InitializeComponent();
    UpdateCurList();
    comboCur.DataSource = curList;
    comboCur.ValueMember = null;
    comboCur.DisplayMember = "FullName";
}
Apostrofix
  • 2,140
  • 8
  • 44
  • 71