I've read this solution: How do I make a ListBox refresh its item text?
But I'm still having no luck getting the text displayed in the listBox to update when the object's property changes.
public partial class Form1 : Form
{
public BindingList<Channel> chanList = new BindingList<Channel>();
private void Form1_Load(object sender, EventArgs e)
{
lbChannels.DisplayMember = "Display";
lbChannels.DataSource = chanList;
}
}
public class Channel
{
public string Display
{
get
{
return ToString();
}
}
public override string ToString()
{
if(!unread || DateTime.Now.Second % 2 == 0)
return Name;
return "";
}
}
The goal here is to cause the channel name to blink in the listBox if there's unread data in it, but when I test it nothing happens. I've also tried calling lbChannels.Refresh() and lbChannels.Update().
I must be missing something but I can't figure out what. The solution in the other thread seems almost too simple to be true, but I've looked through it several times and I can't find anything else related to the listBox. What am I missing here?
The code is already written in the link you provided, do it the same way.. here's an example for updating:
private void btnUpdate_Click(object sender, EventArgs e)
{
Employee selectedEmployee = (Employee)lstEmployees.SelectedItem;
selectedEmployee.Name = "Joseph";
if (selectedEmployee != null)
{
_employees[selectedEmployee.Id] =selectedEmployee;
}
}
Please do not bind to a Display function that uses a overriden ToString method that works if the Time in Seconds is even, that makes no sense.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.