保存并加载datagridview [英] save and load for datagridview

查看:93
本文介绍了保存并加载datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




//for save to file
if (dlgSave.ShowDialog() == DialogResult.OK)
            {

                //create the new file using the name of save dialog box
                FileStream fleProduction = new FileStream(dlgSave.FileName, FileMode.Create, FileAccess.Write, FileShare.Write);
                BinaryWriter bnrProduction = new BinaryWriter(fleProduction);

                //write each value in the file
                bnrProduction.Write(textBox1.Text);
                bnrProduction.Write(label1.Text);
}

//for load file
private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dlgOpen.ShowDialog() == DialogResult.OK)
            {
                FileStream fleProduction = new FileStream(this.dlgOpen.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                BinaryReader bnrProduction = new BinaryReader(fleProduction);
               

                textBox1.Text = bnrProduction.ReadString();
                label1.Text = bnrProduction.ReadString();
}



我无法编写datagridview单元格值的代码,如文本框和标签。

i想要加载并保存到datagridview单元格值的文件。

datagridview有5列和6行



任何人为保存文件和加载文件的datagridview单元格值编写代码从文件中检索数据。



谢谢


iam not unable to write the code for datagridview cell values like textboxes and labels.
i want to load and save to file for datagridview cell values.
datagridview have 5columns and 6 rows

anybody write code for datagridview cell values for save file and load file for retrive data from file.

thanks

推荐答案





要填充Datagrid,您需要将其与任何数据集或数据表连接。



要从Gridview加载或保存数据,它很容易保存文件格式为XML或JSON格式。



您也可以使用数据集直接导出为XML格式。



您可以浏览Gridview来制作自定义数据表或数据集..



如果您不需要创建数据表或数据集,那么可以通过网格中的每一行,然后转换为Datarow然后执行wh在任何时候你需要用它...





谢谢,

Ullas
Hi,

To fill a Datagrid you need to connect it with any Dataset or Datatable.

To load or save data from Gridview its easy to save the file in to XML or JSON format.

You can also use Dataset to export directly to XML format.

You can travel through the Gridview to make a custom datatable or dataset..

if you don't need to create a datatable or data set, then travel through each rows in the grid and then convert in to Datarow and then do what ever you need to do with it...


Thanks,
Ullas


这篇关于保存并加载datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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