El cuadro de lista no mostrará valor
Desde mi control de usuario intenté mostrar valor dentro de un cuadro de lista llamado PersonList
Código de control de usuario:
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 clase NotifiablePerson:
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");
}
}
}
Pero el cuadro de lista solo muestra una lista deSMS.NotificablePersona , no el valor real que especifiqué. Aquí pongovaluemember
. Y funciona correctamente y muestra valores relacionados en sidebox. Pero solo el cuadro de lista no muestra el valor correcto.
¿Qué está mal con este código?