[英]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.