items是用addobject加入的
savetofile只能保存str
怎样正确序列化对象?

解决方案 »

  1.   

    你连对象也要保存吗?
         
      那就用TWriter试试吧!
      

  2.   

    protected void btnLeft_Click(object sender, EventArgs e)
            {
                string value = "";
                int itemCount = ListBox1.Items.Count;
                if (ListBox1.Items.Count > 0)
                {
                    if (ListBox1.SelectedIndex >= 0)
                    {
                        for (int i = 0; i < itemCount; i++)
                        {
                            if (ListBox1.Items[i].Selected)
                            {
                                ListBox2.Items.Add(ListBox1.Items[i]);
                            }
                        }
                        for (int i = 0; i < itemCount; i++)//这个循环需要注意itemCount;下面每删除一个item,listbox的item数量就会少一个,所以此
                        {                                               //处不能使用 ListBox1.Items.Count!!!否则会删除不彻底!!!
                            ListBox1.Items.Remove(ListBox1.SelectedItem);
                        }
                    }
                    else
                    {
                        value = "alert('请在右侧选择科室!');";
                        ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "key", value, true);
                    }
                }
                else
                {
                    value = "alert('右侧无科室!');";
                    ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "key", value, true);
                }
            }
      

  3.   

    建议楼主看一下TObjectList,可能会满足你的要求。
      

  4.   

    TObjectList没有从tpersistence继承,怎么会序列化???还有什么办法
      

  5.   

    WriteComponentResFile
    ReadComponentResFile
    试一下,保存tcompnent及其属性
      

  6.   

    楼主需要做的是自己实现一种序列化的机制,也就是自己给每一个ITEM定一个数据结构,哪一部分是ITEM本身的属性,哪一部分是对象的属性。然后用此格式循环把数据都写到文件中。读出来的时候,自己根据自己的格式,来进行反序列化,把数据写回到列表中就可以了。