Click here to Skip to main content
15,894,106 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I had taken one datagridview as dgv1
In that add one column as Day
I want a user can type only numeric value in column's cells.
how can do that?
Posted
Comments
Sandeep Mewara 4-May-11 10:43am    
Tried anything? Even a search here at CP would had given you similar discussed questions.

you can set filter text of ajax. to do that.

<cc1:FilteredTextBoxExtender ID="FilteredTextBoxExtender4" runat="server" FilterType="Numbers"
                                                            TargetControlID="txtNo">
                                                        </cc1:FilteredTextBoxExtender>
 
Share this answer
 
v3
The following assumes a form with a datagridview having one column named "Day." The Form_Load sets the column to have a ValueType of "Integer"; if a non-integer is entered, the DataError method catches that and I open a MsgBox. I also added a check for the Day number to force it to be between 1 and 31 -- the check is done when the CellValueChanged method fires.

Public Class Form1
Dim ex As System.Windows.Forms.DataGridViewDataErrorEventArgs
Private Sub DataGridView1_CellValueChanged( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles DataGridView1.CellValueChanged
If e.RowIndex >= 0 Then
If DataGridView1.Rows(e.RowIndex).Cells("Day").Value < 1 _
Or DataGridView1.Rows(e.RowIndex).Cells("Day").Value > 31 Then
DataGridView1_DataError(Me, ex)
DataGridView1.CancelEdit()
End If
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.Columns("Day").ValueType = GetType(Integer)
Show()
End Sub
Private Sub DataGridView1_DataError( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) _
Handles DataGridView1.DataError
MsgBox("An input error occurred. The cell you are editing " _
& "only allows NUMERIC values; please correct.", _
MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Oops!")
End Sub
End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900