标题:datagridview问题
只看楼主
guojun1119
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2012-9-9
结帖率:76.92%
已结贴  问题点数:16 回复次数:2 
datagridview问题
  【datagridview中】
      ID    NAME   VALUE
      1    兔子     3
      2     兔子    5
      3     猫      2
      4     猫      4
      5     猫      1
      6     狗      5
    ...    ...    ...
     【问题】我想把属于一类的值放到一个数组里面,应该怎么做例如:[3,5],[2,4,1][5]
           int n = this.dataGridView1.Rows.Count;
            ArrayList nums = new ArrayList();
            for (int i = 0; i < n;i++ )
            {
                String stringValue = this.dataGridView1.Rows[i].Cells[1].Value as string;
                switch (stringValue)
                {
                    case "兔子":
                        double a = Convert.ToDouble(dataGridView1.Rows[i].Cells[2].Value);
                        nums[i] = a;      【报错】索引超出范围。必须为非负值并小于集合大小。参数名: index
                        break;  
                    case "猫":
                        double b = Convert.ToDouble(dataGridView1.Rows[i].Cells[2]);
                        nums[i] = b;
                        break;
                    case "狗":
                        double c = Convert.ToDouble(dataGridView1.Rows[i].Cells[2]);
                        nums[i] = c;
                        break;
具体应该怎么改,请详细解释下,谢谢!
搜索更多相关主题的帖子: 兔子 
2013-01-18 22:46
fily1314
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:166
专家分:1190
注 册:2007-7-18
得分:8 
把ArrayList nums = new ArrayList();这行代码改成数组
double[] nums = new double[n];
2013-01-19 00:30
yinniannian
Rank: 9Rank: 9Rank: 9
来 自:河北省石家庄
等 级:蜘蛛侠
威 望:2
帖 子:256
专家分:1007
注 册:2011-5-13
得分:8 
nums.add(值)

代做小型软件。
QQ:449795473
2013-01-19 08:52



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-397034-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.555232 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved