读书人

vb.net中怎么限定DataGridview的某列只

发布时间: 2013-07-08 14:13:00 作者: rapoo

vb.net中如何限—ataGridview的某列只能输入数字
我在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

读书人网 >VB Dotnet

热点推荐