我要读出文本文档的内容到datagridview中,结果最后总有一行空行,本人是新手,请高手帮忙指点一下,谢谢!!!
StreamReader str = File.OpenText(@"D:\\123.txt"); string strLine = ""; while ((strLine = str.ReadLine()) != null)
{
this.dataGridView1.Rows.Add(strLine.Trim());
}
StreamReader str = File.OpenText(@"D:\\123.txt"); string strLine = ""; while ((strLine = str.ReadLine()) != null)
{
this.dataGridView1.Rows.Add(strLine.Trim());
}
{
if(strLine!="" && strLine!="\r\n")
{
this.dataGridView1.Rows.Add(strLine.Trim());
}
}
{
if(strLine!="" && strLine!="\r\n")
{
this.dataGridView……这样就可以了,我试过了,因为最后读出来的肯定是空字符串
{
this.dataGridView1.Rows.Add(strLine.Trim());
}
去试一下,我用过这个了
{
if(strLine!="" && strLine!="\r\n" && strLine!="\r" && strLine!="\n")))
{
this.dataGridView1.Rows.Add(strLine.Trim());
}
}
string strLine = "";
while ((strLine = str.ReadLine()) != null)
{
if (strLine.Length == 0) continue;//跳过空行
this.dataGridView1.Rows.Add(strLine.Trim());
}
string strLine = "";
while (!string.IsNullOrEmpty(strLine = str.ReadLine()))
{
if (strLine.Length == 0) continue;//跳过空行
this.dataGridView1.Rows.Add(strLine.Trim());
}