本文介绍了拆分字符串并考虑datagridview问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有字符串,我正在使用此代码分割此字符串:
split = ast.Split(new Char [] {'!'}};
之后我正在制作DataTable
DataTable table = new DataTable();
DataGridViewRow addRow = new DataGridViewRow();
int columnCount = 27;
for(int i = 1; i< = columnCount; i ++)
{
DataColumn col = new DataColumn(col+ i);
table.Columns.Add(col);
}
DataRow row = table.NewRow();
之后我希望这个拆分的字符串进入单元格而我正在使用我正在尝试的代码但是有一个问题我的字符串长度可能是27或者27 + 27我的字符串长度是常数27,所以我有第27列,但是如果我的代码(我尝试过的话)看到长度超过27就错了我
附加信息:找不到第27列。
请帮我这样做
我尝试了什么:
for(int i = 0; i< = split.length; i ++)
{
row [i] = split [i];
}
table.Rows.Add(row);
}
this.dataGridView1.DataSource = table;
解决方案
i have string and i am splting this string using this code :
split = ast.Split(new Char[] { '!' });
after that i am making DataTable
DataTable table = new DataTable();
DataGridViewRow addRow = new DataGridViewRow();
int columnCount = 27; for (int i = 1; i <= columnCount; i++) { DataColumn col = new DataColumn("col" + i); table.Columns.Add(col); }
DataRow row = table.NewRow();
after this i want to this splited string take into cells and i am using code that i am trying but there is 1 problem my string length may be 27 or 27+27 my string length is growig with constant number 27 soo i have columns 27 but if my code(what i have tryed) see that length is more then 27 it is erroring me
Additional information: Cannot find column 27.
plz help me do this
What I have tried:
for (int i = 0; i <= split.length; i++) { row[i] = split[i]; } table.Rows.Add(row); } this.dataGridView1.DataSource = table;
解决方案
这篇关于拆分字符串并考虑datagridview问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!