Manipulating what will be displayed in the Displaymember of a Checklistbox

Asked

Viewed 82 times

0

I have a Model class:

  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; }
    }
}

Which is filled in through the information recorded in the database. I need my Displaymember to have the Name + Date + Time + Climodel.Name And I need Valuemember to match ID.

I’m trying to do it this way

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

But the information I put in doesn’t show up. How I make information appear the way I need it?

  • "Gets or sets a string that specifies a Property of the Objects contained in the list box Whose Contents you want to display." The Member display must be a property of your datasource. If possible, create a property with a get { Return Name + Date + Time + Weather };

  • There’s no way to concatenate?

  • Not with Displaymember. Another possibility is to create an anonymous property to represent Displaymember.

  • how I would create an anonymous property to represent Displaymember.

1 answer

0


If no value is set for the property DisplayMember by default the return of the method will be displayed ToString() 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);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.