Accepting numeric values within a range in a DataGrid

partham

Active member
Joined
Dec 27, 2005
Messages
41
Location
Kolkata, India
Programming Experience
10+
Dear Sir,

We would like to program a TextBox in a DataGrid to accept only numbers in a specified range. For the same, we have created a class NumericDataGridTextBox. Now, everything else works but for the range check. Our understanding is that the Commit method is invoked when the value has to be accepted by the TextBox. This is happening. However, we find that the RowNumber passed to this function is that of the new row pointed to in the DataGrid and as a result the value to be evaluated is not as desired. Please find attached our code. Please suggest us where we are going wrong and where is the concept wrong.

Thanks in advance.

Regards,
VB.NET:
[SIZE=2][COLOR=#008000]=======================================================[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]''**************************************************************************[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]''@author Partha Majumdar[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]''Purpose: This function accepts a value in the Text box if it is within range[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]''[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]''Creation/Modification History :[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'' 01-Oct-2006 Created[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]''[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]''**************************************************************************[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'Protected Overrides Function Commit(ByVal objSource As System.Windows.Forms.CurrencyManager, ByVal iRowNumber As Integer) As Boolean[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' Dim l_objValue As Object[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' Dim l_dblValue As Double[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' Dim l_lValue As Long[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' Dim l_iValue As Integer[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' Dim l_sValue As Short[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' Try[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' l_objValue = Me.GetColumnValueAtRow(objSource, iRowNumber)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' If l_objValue.GetType Is GetType(Double) Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' l_dblValue = CType(l_objValue, Double)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' If l_dblValue >= MinimumValue And l_dblValue <= MaximumValue Then MyBase.Commit(objSource, iRowNumber)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' ElseIf l_objValue.GetType Is GetType(Long) Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' l_lValue = CType(l_objValue, Long)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' If l_lValue >= MinimumValue And l_lValue <= MaximumValue Then MyBase.Commit(objSource, iRowNumber)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' ElseIf l_objValue.GetType Is GetType(Integer) Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' l_iValue = CType(l_objValue, Integer)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' If l_iValue >= MinimumValue And l_iValue <= MaximumValue Then MyBase.Commit(objSource, iRowNumber)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' ElseIf l_objValue.GetType Is GetType(Short) Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' l_sValue = CType(l_objValue, Short)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' If l_sValue >= MinimumValue And l_sValue <= MaximumValue Then MyBase.Commit(objSource, iRowNumber)[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' End If[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' Catch ex As Exception[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' Finally[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' l_objValue = Nothing[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' l_dblValue = Nothing[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' l_lValue = Nothing[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' l_iValue = Nothing[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' l_sValue = Nothing[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]' End Try[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'End Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]=======================================================[/COLOR][/SIZE]
 
Last edited by a moderator:
Back
Top