如何在if语句中使用数据网格视图的单元格值。 [英] How can I use a cell value of data grid view in an if statement.
本文介绍了如何在if语句中使用数据网格视图的单元格值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
禁用按钮,如果位(数据网格视图中显示为复选框,则为true或false)当前行的值从数据网格视图中的单元格列为true。使用下面的代码,即使列值为false,也只需禁用按钮。
我尝试过:
if(datagridview1.Currentrow.Cells [columnname]。Value = true)
{
button1.Enabled = false;
}
disable a button if bit(true or false, in data grid view it is shown as checked box) value of a current row is true from a cell column in data grid view. Using the code below just disable the button even if the column value is false.
What I have tried:
if(datagridview1.Currentrow.Cells["columnname"].Value=true)
{
button1.Enabled=false;
}
推荐答案
您正在使用单个等号,这使得赋值转换为true。改为==。此外,Value可能是一个Object,因此您可能需要先转换为字符串或布尔值。
You are using a single equal sign which makes an assignment which resolves to true. Change to ==. Also, Value might be an Object so you may need to convert to string or boolean first.
这篇关于如何在if语句中使用数据网格视图的单元格值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文