Datagridview Column是否接受小数? [英] Datagridview Column accept decimals?

查看:77
本文介绍了Datagridview Column是否接受小数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在下面的代码中允许小数?



  ElseIf (e.ColumnIndex =  9 然后 ' 仅检查第9列的数值 
Dim As String = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()
对于 每个 c As 字符
如果 字符 .IsDigit(c)然后
MessageBox.Show( 请输入数值。 输入错误,MessageBoxButtons.OK,MessageBoxIcon。错误
DataGridView1.Rows(e.RowIndex).Cells( e.ColumnIndex).Value = 字符串 .Empty
退出
结束 如果
Next

解决方案

我的VB有点生疏,但是这样的事情应该这样做:



  ElseIf (e.ColumnIndex =  9 然后 ' 检查数值仅适用于第9列 
Dim 作为 String = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()
Dim dTmp 作为 十进制
如果 < span class =code-keyword>不 十进制 .TryParse(value,dTmp)然后 MessageBox.Show( 请输入数值。 输入错误,MessageBoxButtons.OK,MessageBoxIcon。错误


How do i allow decimals in the below code?

ElseIf (e.ColumnIndex = 9) Then   ' Checking numeric value for Column 9 only
            Dim value As String = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()
            For Each c As Char In value
                If Not Char.IsDigit(c) Then
                    MessageBox.Show("Please enter a numeric value.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = String.Empty
                    Exit Sub
                End If
            Next

解决方案

My VB is a bit rusty, but something like this should do it:

ElseIf (e.ColumnIndex = 9) Then   ' Checking numeric value for Column 9 only
            Dim value As String = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()
            Dim dTmp As Decimal
            If Not Decimal.TryParse(value,dTmp) Then MessageBox.Show("Please enter a numeric value.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)


这篇关于Datagridview Column是否接受小数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆