首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

vb.net中怎么限定DataGridview的某列只能输入数字

2013-07-08 
vb.net中如何限定DataGridview的某列只能输入数字我在datagridview中需要限制某列只能输入输入数字,不能输

vb.net中如何限定DataGridview的某列只能输入数字
我在datagridview中需要限制某列只能输入输入数字,不能输入其它的,同时如果数字是3.3.3这样的也是不合理的。请问这样的代码要怎么写呢 DataGridView VB.NET 输入限制
[解决办法]

引用:
Quote: 引用:

可以用这个
public DataGridViewTextBoxEditingControl CellEdit = null;





private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)

{

    if (this.dataGridView1.CurrentCellAddress.X == 4)

    {

        CellEdit = (DataGridViewTextBoxEditingControl)e.Control;

        CellEdit.SelectAll();

        CellEdit.KeyPress += Cells_KeyPress; //绑定事件

    }

}




private void Cells_KeyPress(object sender, KeyPressEventArgs e) //自定义事件

{

    if ((this.dataGridView1.CurrentCellAddress.X == 4) 
[解决办法]
 (this.dataGridView1.CurrentCellAddress.X == 5) 
[解决办法]
 (this.dataGridView1.CurrentCellAddress.X == 6))

    {

        if (!(e.KeyChar >= '0' && e.KeyChar <= '9')) e.Handled = true;

        if (e.KeyChar == '\b') e.Handled = false;

    }

}

我需要的是vb.net的啊,这个没法用啊


http://www.developerfusion.com/tools/convert/csharp-to-vb/
[解决办法]
 Private Sub DataGridView1_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating 


        If DataGridView1.Rows(e.RowIndex).IsNewRow Then Exit Sub
        If e.ColumnIndex = 4 Then
            If IsNumeric(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value) = False Then
                e.Cancel = True
                MsgBox("请输入数字或小数")
            End If
        End If
    End Sub

热点排行