We had quite lot problems with the GridViewMaskBoxColumn in Numeric masktype. We use "," not "." for decimal point that coused lot of bugs in the GridViewMaskBoxColumn. And altought the grid was setted to our localization setting the GridViewMaskBoxColumn still used the point. So here is the sollution what we figured out with the help of the telerik team.
This will hold the new row after we begin the edit.
Private newRow As Telerik.WinControls.UI.GridViewDataRowInfo |
Private Sub RadGridView1_RowsChanged(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.GridViewCollectionChangedEventArgs) Handles RadGridView1.RowsChanged
If e.Action = Telerik.WinControls.Data.NotifyCollectionChangedAction.Add Then
newRow =
TryCast(e.NewItems(0), Telerik.WinControls.UI.GridViewDataRowInfo)
End If
End Sub
In CellEndEdit event we replace the point with the comma. If the row has an index of -1 then thats a newrow.
Private Sub RadGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCellEventArgs) Handles RadGridView1.CellEndEdit |
If e.RowIndex >= 0 And e.RowIndex < RadGridView1.Rows.Count And e.ColumnIndex >= 0 And e.ColumnIndex < RadGridView1.Columns.Count Then |
If RadGridView1.Columns(e.ColumnIndex).GetType.Name = "GridViewMaskBoxColumn" Then |
Dim cell As Telerik.WinControls.UI.GridViewCellInfo = RadGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex) |
cell.Value = cell.Value.ToString().Replace("."c, ","c) |
End If |
Else |
If newRow IsNot Nothing Then |
For Each cella As Telerik.WinControls.UI.GridViewCellInfo In newRow.Cells |
If cella.Value IsNot Nothing And cella.ColumnInfo.GetType.Name = "GridViewMaskBoxColumn" Then |
cella.Value = cella.Value.ToString().Replace("."c, ","c) |
End If |
Next |
End If |
End If |
End Sub |
In the CreateRow we can give starting values for the cells if they were left blank.
Private Sub RadGridView1_CreateRow(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.GridViewCreateRowEventArgs) Handles RadGridView1.CreateRow |
For i As Int32 = 0 To e.RowInfo.Cells.Count - 1 |
If IsDBNull(e.RowInfo.Cells(i).Value) Then |
If RadGridView1.Columns(i).GetType.Name = "GridViewMaskBoxColumn" Then |
Dim oszlop As Telerik.WinControls.UI.GridViewMaskBoxColumn |
oszlop = TryCast(RadGridView1.Columns(i), Telerik.WinControls.UI.GridViewMaskBoxColumn) |
e.RowInfo.Cells(i).Value = "0,00" |
End If |
Else |
If e.RowInfo.Cells(i).Value = "" Then |
If RadGridView1.Columns(i).GetType.Name = "GridViewMaskBoxColumn" Then |
Dim oszlop As Telerik.WinControls.UI.GridViewMaskBoxColumn |
oszlop = TryCast(RadGridView1.Columns(i), Telerik.WinControls.UI.GridViewMaskBoxColumn) |
e.RowInfo.Cells(i).Value = "0,00" |
End If |
End If |
End If |
Next |
End Sub |