如何将datagridview数据传输到锯齿状数组 [英] How can I transport datagridview data to jagged array
本文介绍了如何将datagridview数据传输到锯齿状数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将datagridview数据传输到锯齿状阵列但出于某种原因但我无法成功
错误是:
Hi, I am trying to transport datagridview data to jagged array for some reason but I couldn't succeed
the error is:
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: The input line was not in the correct format.
我的datagridview数据是这样的;
my datagridview data is like;
|0.35|1.58|0.82|1.78|0.85|1.55|1|0|0|}
我的尝试:
What I have tried:
string linex= "";
string[] correction= null;
for (int i=0;i<= rowcount-1;i++)
{
for (int j=0;j<= colmcount-1;j++)
{
linex= linex.ToString()+" " + dataGridView1.Rows[i].Cells[j].Value.ToString();
}
correction= linex.Split(',');
rowdataexample[i] = new double[columncnt];
for (int k = 0; k <= colmcount-1; k++)
{
rowdataexample[i][k] = double.Parse(correction[k]);
}
correction= null;
linex= "";
}
推荐答案
为此添加逗号
add comma to this
linex= linex.ToString()+"," + dataGridView1.Rows[i].Cells[j].Value.ToString();
注意:
使用 Double.TryParse Method(System) [ ^ ]将字符串转换为double
使用 String.Trim方法(系统) [ ^ ]以避免开始时不需要的空间字符串的结尾。
Note:
use Double.TryParse Method (System)[^] for converting string to double
use String.Trim Method (System)[^] to avoid unwanted space in the beginning and end of the string.
这篇关于如何将datagridview数据传输到锯齿状数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文