繁体   English   中英

datagridview单元格的比较值如何为十进制类型

[英]how compare value of datagridview cell is of decimal type or not

我写了这段代码

(DataGridViewRow  dgRow in dgvMarksEntryForClass.Rows)
{
     if (dgRow.Cells["dgcolMarksObtain"].Value.GetType is decimal)
     {
         //some action
     }
     else { 
         //some action
     }
}

我如何检查是否值

dgRow.Cells["dgcolMarksObtain"].Value.GetType

是十进制类型的?

您可以使用Decimal TryParse()方法。

(DataGridViewRow  dgRow in dgvMarksEntryForClass.Rows)
{
    Decimal cellValue;
    if (Decimal.TryParse(dgRow.Cells["dgcolMarksObtain"].Value, out cellValue)
    {
         //some action
    }
    else
    {
        //some action
    }
}
decimal value;
if(Decimal.TryParse(dgRow.Cells["dgcolMarksObtain"].Value.ToString(), out value))
  // It's a decimal
else
  // No it's not.

尝试这个-

(DataGridViewRow  dgRow in dgvMarksEntryForClass.Rows)
{
     if (dgRow.Cells["dgcolMarksObtain"].Value.GetType() is decimal)
     {
         //some action
     }
     else { 
         //some action
     }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM