Other ways in overriding 'value' Property in DatagridViewCell

jfecardona

Member
Joined
May 4, 2011
Messages
7
Location
Alegria Cebu, Philippines
Programming Experience
1-3
Hi, I was trying to override value property in datagridviewcell but it says it is not overridable. Is there any other way to do it? The situation is, i want to check the value first if it is valid before throwing it back.. I tried to do it in textbox.Text like this:

Public Overrides Property Text() As String
Get
Return MyBase.Text
End Get
Set(ByVal value As String)
if isnumeric(value) Then
MyBase.Text = value
Else
MyBase.Text = 0
End If
End Set
End Property

Now I want to do it using datagridviewcell's property which is "value"
ex: datagrid1.item(0,0).value = ""
 
I was able to create a new textbox column in datagridview using inheritance. I added a property called TextType where the user will just have to select whether the accepted values in this column are only numbers or only Letters, etc. But I was having a bit of confusion in checking the assigned value. I can only check it on Keypress. But when I say in the code datagrid.Item(0,0).value = 'abcde' it still accepts it since it is programatically set and not keypressed. But Anyways, I haven't tried using CellValidating yet.. Let's see if i can solve it through this.. thanks!
 
This is how the DataGridViewCell.Value property is implemented:
VB.NET:
Public Property Value As Object
    Get
        Return Me.GetValue(Me.RowIndex)
    End Get
    Set(ByVal value As Object)
        Me.SetValue(Me.RowIndex, value)
    End Set
End Property
The SetValue method is overridable.
 
Back
Top