向一个数组添加循环的值的问题

xiaotiange 2010-08-21 10:00:34

byte[] strarr;
int rowcount = 0;
string value="";
foreach (DataGridViewRow dr in this.dataGridView1.Rows)
{
DataGridViewCheckBoxCell cbx = dr.Cells[0] as DataGridViewCheckBoxCell;
strarr = new string[rowcount];

try
{
if ((bool)cbx.Value)
{
rowcount++;
value = (string)dr.Cells[1].Value;
}
//strarr.ToList<string>().Add(value);
//strarr.ToArray();

}
catch
{
return;
}

}
strarr.ToList<string>().Add(value);
strarr.ToArray();


如上代码所示,在一个datagridview中,第一列为DataGridViewCheckBoxColumn ,第二列为DataGridViewTextBoxColumn
,勾选哪行就把哪行的值添加到数组里面,数组大小是动态的,现在的问题是 strarr总是空的…… ,第二列的值能取出来但没有添加到数组里面,数组长度也能确定……
求助~!
...全文
300 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaotiange 2010-08-23
  • 打赏
  • 举报
回复
其实发帖后一个小时就弄明白了,不过还是要谢谢你们哈
teerhu 2010-08-21
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 peter200694013 的回复:]
List<byte> strarr = new List<byte>() ;
---》
List<string> strarr = new List<string>();
[/Quote]
up
Peter200694013 2010-08-21
  • 打赏
  • 举报
回复
List<byte> strarr = new List<byte>() ;
---》
List<string> strarr = new List<string>();
Peter200694013 2010-08-21
  • 打赏
  • 举报
回复

List<byte> strarr = new List<byte>() ;
int rowcount = 0;
string value = "";
foreach (DataGridViewRow dr in this.dataGridView1.Rows)
{
DataGridViewCheckBoxCell cbx = dr.Cells[0] as DataGridViewCheckBoxCell;
strarr = new string[rowcount];

try
{
if ((bool)cbx.Value)
{
rowcount++;
value = (string)dr.Cells[1].Value;
}
strarr.Add(value);

}
catch
{
return;
}

}
yinjianjing 2010-08-21
  • 打赏
  • 举报
回复
每天回帖即可获得10分可用分!
wuyq11 2010-08-21
  • 打赏
  • 举报
回复
可变数组使用List<string> lst=new List<string>();
等保存

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧