【发布时间】:2014-09-25 09:44:52
【问题描述】:
大家好,
如上图所示,我想将文本文件中的十进制数字列添加到数据网格控件。
下面是我的代码sn-p
List<string> str = new List<string>();
String st = "";
int k = 0;
string[] s ;
//Path to write contents to text file
string filename = @"E:\Vivek\contentcopy\clientlist.txt";
Form.CheckForIllegalCrossThreadCalls = false;
OpenFileDialog ofd = new OpenFileDialog();
ofd.FileName = "";
ofd.ShowDialog();
st = ofd.FileName;
if (string.IsNullOrEmpty(ofd.FileName))
return;
string Name = "", No1 = "",No2="";
string[] lines = File.ReadAllLines(st).Where(sw => !string.IsNullOrWhiteSpace(sw)).ToArray();
for (int i = 0; i < lines.Length; i++)
{
if (lines[i].Contains("VENTURA SECURITIES LIMITED (NSE F&O)")) continue;
if (lines[i].Contains("ALL EXCHANGES DERIVATIVES CLIENTWISE STATEMENT AS ON 16-05-2012")) continue;
if (lines[i].Contains("-------------------------------------------------------")) continue;
s = lines[i].Split(' ');
if (s[0] == "PARTY" || s[0] == "") continue;
int z;
Name = "";
for (z = 1; z < s.Length; z++)
{
if (s[z] == "") continue;
if (s[z].Contains('.'))
{
No1+=s[z]+" ";
No2 = No1 + " ";
}
else
{
Name += s[z];
str.Add(s[0]+" "+Name);
}
}
dataGridView1.Rows.Add();
dataGridView1.Rows[k].Cells[0].Value = s[0];
dataGridView1.Rows[k].Cells[1].Value = Name;
dataGridView1.Rows[k].Cells[2].Value = No1;
dataGridView1.Rows[k].Cells[3].Value = No2;
k++;
}
File.WriteAllLines(filename, str);
dataGridView1.ReadOnly = true;
}
No1=s[z] 行直接取最后一列的值,即 46,123.19 等。我想从文本文件中获取每一列并将其存储在字符串变量中,然后将其分配给数据网格视图 我希望我的疑问很清楚。如果没有,请告诉我
【问题讨论】:
-
究竟是什么不起作用?您是否遇到错误或值未显示?
-
@DionV。感谢您的回复。实际上,当我分配 no1=s[z] 时,它直接占用最后一列,即 46,123.19 1,990.20 和儿子,我希望将每列分配给一个变量,例如 1st Column,其值为 200.0 0.0
标签: c# datagridview datagrid