首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C# if语句为什么只执行else的,小弟我想根据选中的datagridview的行中的某项值(为Bool型)进行判断

2012-12-26 
C# if语句为什么只执行else的,我想根据选中的datagridview的行中的某项值(为Bool型)进行判断private void

C# if语句为什么只执行else的,我想根据选中的datagridview的行中的某项值(为Bool型)进行判断
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dataGridView1.SelectedRows[0].Cells[9].Value.ToString() == "0")
            {
                FayaoquerenForm frm2 = new FayaoquerenForm(dataGridView1.SelectedRows[0].Cells[0].Value.ToString(), dataGridView1.SelectedRows[0].Cells[2].Value.ToString(), dataGridView1.SelectedRows[0].Cells[3].Value.ToString(), dataGridView1.SelectedRows[0].Cells[7].Value.ToString());
                //所带参数是datagridview选择行的指定列里面的值 
                frm2.ShowDialog();
            }
            else
            {
                MessageBox.Show("此处方药品已取!");
            }
        }

[最优解释]
datagridview中的Bool型要这样判断
把这句
  if (this.dataGridView1.SelectedRows[0].Cells[9].Value.ToString() == "0")
改成
  if (this.dataGridView1.SelectedRows[0].Cells[9].EditedFormattedValue.ToString().Trim() == "True"
这样
[其他解释]
请 ... Debug ...
[其他解释]
断点调试this.dataGridView1.SelectedRows[0].Cells[9].Value.ToString()看是什么
[其他解释]
不知道你的bool型是什么情况下的,是根据sql语句来的,还是根据复选框的选中状态来的,
if (this.dataGridView1.SelectedRows[0].Cells[9].EditedFormattedValue.ToString().Trim() == "True"

这个只对datagridview中第9列为复选框的时候,在有用
[其他解释]

引用:
断点调试this.dataGridView1.SelectedRows[0].Cells[9].Value.ToString()看是什么


[其他解释]
引用:
不知道你的bool型是什么情况下的,是根据sql语句来的,还是根据复选框的选中状态来的,
if (this.dataGridView1.SelectedRows[0].Cells[9].EditedFormattedValue.ToString().Trim() == "True"

这个只对datagridview中第9列为复选框的时候,在有用
可以了谢谢
[其他解释]
bool result=this.dataGridView1.SelectedRows[0].Cells[9].EditedFormattedValue.ToString().Trim();
if(result);;
else //
[其他解释]
不错!== "True"

热点排行