我制作了这段代码
(DataGridViewRow dgRow in dgvMarksEntryForClass.Rows)
{
if (dgRow.Cells["dgcolMarksObtain"].Value.GetType is decimal)
{
//some action
}
else {
//some action
}
}
如何检查
的值是否为dgRow.Cells["dgcolMarksObtain"].Value.GetType
是十进制类型吗?
答案 0 :(得分:2)
您可以使用十进制TryParse()方法。
(DataGridViewRow dgRow in dgvMarksEntryForClass.Rows)
{
Decimal cellValue;
if (Decimal.TryParse(dgRow.Cells["dgcolMarksObtain"].Value, out cellValue)
{
//some action
}
else
{
//some action
}
}
答案 1 :(得分:0)
decimal value;
if(Decimal.TryParse(dgRow.Cells["dgcolMarksObtain"].Value.ToString(), out value))
// It's a decimal
else
// No it's not.
答案 2 :(得分:-2)
试试这个 -
(DataGridViewRow dgRow in dgvMarksEntryForClass.Rows)
{
if (dgRow.Cells["dgcolMarksObtain"].Value.GetType() is decimal)
{
//some action
}
else {
//some action
}
}