关于ListBox与CheckedListBox的Refresh函数的问题

supergoalcn 2005-08-18 03:48:15
首先定义一个类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?
...全文
241 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
SkyYear2004 2005-08-19
  • 打赏
  • 举报
回复
Try With C# 2005 FRAMEWORK 2

just the same.

bug ? or not ?
SkyYear2004 2005-08-18
  • 打赏
  • 举报
回复
public class myListBox : System.Windows.Forms.ListBox
{
public override void Refresh()
{
for (int i = 0; i <= base.Items.Count -1 ; i++)
{
base.RefreshItem(i);
}
base.Refresh ();
}
}

拿点分数.哈哈

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧