[英]how compare value of datagridview cell is of decimal type or not
I made this code 我写了这段代码
(DataGridViewRow dgRow in dgvMarksEntryForClass.Rows)
{
if (dgRow.Cells["dgcolMarksObtain"].Value.GetType is decimal)
{
//some action
}
else {
//some action
}
}
how do I check whether the value of 我如何检查是否值
dgRow.Cells["dgcolMarksObtain"].Value.GetType
is of decimal type? 是十进制类型的?
You can use the Decimal TryParse() method. 您可以使用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.
Try this- 尝试这个-
(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.