如何在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.