dataGridView读写文本
constant con = new constant();
private void loadlistbox2()
{
datagridview1.columncount = 1;
string z;
if (file.exists(".//allitems.txt"))
{
filestream fs = new filestream(".//allitems.txt", system.io.filemode.open, system.io.fileaccess.read);
streamreader sr = new streamreader(fs, system.text.encoding.getencoding("utf-8"));
try
{
while (true)
{
z = sr.readline();
if (z == null) break;
datagridview1.rows.add(z);
}
}
finally
{
sr.close();
fs.dispose();
fs.close();
}
}
}
string st = "";
private void savetestitem()
{
// datagridview1.columncount = 1;
if (file.exists(".//allitems.txt"))
{
filestream fs = new filestream(".//allitems.txt", system.io.filemode.open, system.io.fileaccess.write);
streamwriter sr = new streamwriter(fs, system.text.encoding.getencoding("utf-8"));
try
{
for (int i = 0; i < 22; i++)
{
for (int j = 0; j < 1; j++)
{
st = st + datagridview1.rows[i].cells[j].value;
}
sr.writeline(st);
st = "";
//for (int i = 0; i < datagridview1.rows.count; i++)
//{
// sr.writeline(datagridview1.rows[i].cells);
// }
}
}
finally
{
sr.close();
fs.dispose();
fs.close();
}
}
}
上一篇: PHP获取网站域名和地址的代码
下一篇: ShoppingCart