Manipulating what will be displayed in the DisplayMember of a CheckListBox

0

I have a class Model:

  class pessoaModel
  {
    int id;
    DateTime data;
    TimeSpan hora;
    CliModel ID_Cliente = new CliModel ();

    public string Nome 
    {
        get { return nome; }
        set { nome = value; }
    }

    public int ID
    {
        get { return id; }
        set { id = value; }
    }

    public TimeSpan Hora
    {
        get { return hora; }
        set { hora = value; }
    }


    public DateTime Data
    {
        get { return data; }
        set { data = value; }
    }        

    public CliModel cliModel 
    {
        get { return CliModel ; }
        set { CliModel = value; }
    }
}

That is populated through the information recorded in the database. I need my DisplayMember to have the Name + Date + Time + CliModel.Name I need the ValueMember to be equal to ID.

I'm trying to do as follows

        chkAtendimento.DataSource = listaAtendimento;
        chkAtendimento.DisplayMember = "Nome" + "Data" + "Hora" + "CliModel.Nome" 
        chkAtendimento.ValueMember = "Id";

But the information I put in does not appear. How do I get the information to appear the way I need it?

    
asked by anonymous 24.02.2016 / 14:50

1 answer

0

If no value is set for the DisplayMember property by default, the return of the ToString() method is displayed, which is a method that allows overloading. With this you can put in your class a code similar to the following in your class pessoaModel

public override string ToString()
{
  return string.Format("{0} {1} {2} {3}", Nome, Data, Hora, CliModel.Nome);
}
    
24.02.2016 / 17:05