关于ListBox与CheckedListBox的Refresh函数的问题
首先定义一个类Person,并重写ToString函数
public class Person
{
public string name;
public Person(string name)
{
this.name = name;
}
public override string ToString()
{
return "Name: " + name;
}
}
然后创建一个Windows应用程序,在窗体上加入一个ListBox(listBox1)与一个CheckedListBox(checkedListBox1),以及一个按扭用于触发事件。
代码如下:
private void button1_Click(object sender, System.EventArgs e)
{
p1.name = "aaaa";
listBox1.Refresh();
checkedListBox1.Refresh();
}
Person p1,p2,p3;
private void Form1_Load(object sender, System.EventArgs e)
{
p1 = new Person("aa");
p2 = new Person("bb");
p3 = new Person("cc");
listBox1.Items.Add(p1);
listBox1.Items.Add(p2);
listBox1.Items.Add(p3);
checkedListBox1.Items.Add(p1);
checkedListBox1.Items.Add(p2);
checkedListBox1.Items.Add(p3);
}
问题是为什么按下button1后,checkedListBox1中的第一项变量了aaaa,而listBox1仍然是aa?