标题:dategridview求助
只看楼主
xzhsues
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-1-10
结帖率:100%
已结贴  问题点数:20 回复次数:5 
dategridview求助
请教论坛里的各位的大神一个问题。我在C#环境下想将dategridview表里面的数据与指定的字符相比判断。
以下是我的代码
 for (int j = 0; j < GridView1.Rows.Count; j++)
            {
               
                #region 门左移
                    if (GridView1.Rows[j].Cells[1].Value.ToString() == "门左移") //门左面移动           
                    {
                        if (GridView1.Rows[j].Cells[1].Value.ToString() == "1") //信号为1            
                        {
                            MessageBox.Show("finished2");
                        }

                        else
                            if (GridView1.Rows[j].Cells[1].Value.ToString() == "0") //信号为0           
                            {

                            }
                    }
              #endregion
但是系统一直跳出未将对象引用设置到对象的实例。不知道怎么处理。
2013-01-10 20:24
yinniannian
Rank: 9Rank: 9Rank: 9
来 自:河北省石家庄
等 级:蜘蛛侠
威 望:2
帖 子:256
专家分:1007
注 册:2011-5-13
得分:7 
先判断datagridview里面有没有值

代做小型软件。
QQ:449795473
2013-01-10 23:33
xzhsues
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-1-10
得分:0 
我是跟数据库相连。上面显示有数据的。
2013-01-11 09:16
Maick
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:32
帖 子:251
专家分:1314
注 册:2012-9-21
得分:7 
if (GridView1.Rows[j].Cells[1].Value.ToString() == "门左移") //门左面移动           
                    {
                        if (GridView1.Rows[j].Cells[1].Value.ToString() == "1") //信号为1            
                        {
                            MessageBox.Show("finished2");
                        }

                        else
                            if (GridView1.Rows[j].Cells[1].Value.ToString() == "0") //信号为0           
                            {

                            }
                    }
这什么逻辑??GridView1.Rows[j].Cells[1].Value.ToString() == "门左移" 还会  == "1" 还会 == "0"真荒谬!!
2013-01-11 11:09
Maick
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:32
帖 子:251
专家分:1314
注 册:2012-9-21
得分:0 
GridView1.Rows[j].Cells[1].Value.ToString()应该是 :GridView1.Rows[j].Cells[0].Value.ToString()
2013-01-11 11:31
xzhsues
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-1-10
得分:0 
发错了
 #region 门左移
           if (Convert.ToString(GridView1.Rows[j].Cells[1].Value) == "门左移") //门左面移动           
                    {
                        if (Convert.ToString(GridView1.Rows[j].Cells[2].Value) == "1") //信号为1            
                        {
                            MessageBox.Show("finished2");
                        }

                        else
                        if (Convert.ToString(GridView1.Rows[j].Cells[2].Value) == "0") //信号为0           
                        {

                        }
                    }
                现在运行时没有错误。但是它内容读不出来。

[ 本帖最后由 xzhsues 于 2013-1-11 14:06 编辑 ]
2013-01-11 14:00



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




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

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