我如何保存列表框? [英] how I can save a listbox??

查看:79
本文介绍了我如何保存列表框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我如何保存列表框并在每次启动程序时做一些加载工作????
tnx

hello all
how I can save a list box and do thing to load it everytime i start the program???
tnx

推荐答案

private static void SaveListBox(ListBox listBox, string file)
{
    int count = listBox.Items.Count;
    string[] lines = new string[count];
    for (int i = 0; i < count; i++)
    {
        lines[i] = listBox.Items[i].ToString();
    }
    File.WriteAllLines(file, lines);
}

private static void LoadListBox(ListBox listBox, string file)
{
    string[] lines = File.ReadAllLines(file);
    listBox.Items.Clear();
    listBox.Items.AddRange(lines);
}


我不明白您的问题.如果列表框中有东西,它就会以某种方式到达那里,所以只要运行一下,程序就会再次加载它.如果您谈论的是选定的项目,只需将它们保存到文件中,然后在加载程序时,从该数据文件的内容中设置列表框中的选定项.
I don''t understand your question. If you have something in the listbox, it got there somehow, so just runnign the program will load it again.If you''re talking about the selected item(s), just save them to a file, and when the program is loaded, set the selected items in the listbox from that data file''s contents.


这篇关于我如何保存列表框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆