A caixa de listagem não exibirá valor
No meu usercontrol, tentei mostrar o valor dentro de uma caixa de listagem chamada PersonList
Código de controle do usuário:
BindingList<NotifiablePerson> PerSonList = new BindingList<NotifiablePerson>();
SqlCommand prsonListCmd = new SqlCommand("SQL QUERY", conn);
SqlDataReader dr = prsonListCmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
//collect value from database and save inside Fname and Lname variable
NotifiablePerson np = PerSonList.AddNew();
np.FirstName = Fname;
np.LastName = Lname;
}
}
PersonList.DisplayMember = "np.FirstName" + "np.LastName";
PersonList.ValueMember = "np.FirstName";
PersonList.DataSource = PerSonList;
Código de classe da pessoa:
namespace SMS
{
class NotifiablePerson : MyComponentModel.NotifyProperyChangedBase
{
private string _firstName;
public string FirstName
{
get { return _firstName; }
set{
if (this.CheckPropertyChanged<string>("FirstName", ref _firstName, ref value))
{
this.DisplayNameChanged();
}
}
}
private string _lastName;
public string LastName
{
get { return _lastName; }
set{
if (this.CheckPropertyChanged<string>("LastName", ref _lastName, ref value))
{
this.DisplayNameChanged();
}
}
}
public string DisplayName
{
get { return _firstName + " " + _lastName; }
}
private void DisplayNameChanged()
{
this.FirePropertyChanged("DisplayName");
}
}
}
Mas a caixa de listagem exibe apenas uma lista deSMS.NotifiablePerson , não o valor real que eu especifiquei. Aqui eu colocovaluemember
. E funciona corretamente e exibe valores relacionados no sidebox. Mas apenas a caixa de listagem não exibe o valor correto.
O que está errado neste código?