有谁知道如果需要不断往listbox添加数据 为了不占用太多内存 怎么可以做到自动清理里面的数据

解决方案 »

  1.   

                if (listBox1.Items.Count > 100)
                {
                    listBox1.Items.Clear();
                }
                listBox1.Items.Add("hello");
    每次要往listbox添加数据 ,就先判断下当前listbox的项目数量大小,超过100就自动清理,然后再添加数据.
      

  2.   

    if (listBox1.Items.Count > 100)
    {
        listBox1.Items.RemoveAt(0); //把最早的一条删除掉。
    }
    listBox1.Items.Add("hello");