This is a migrated thread and some comments may be shown as answers.

GridViewMaskBoxColumn decimal problems sollutin

1 Answer 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
gabi
Top achievements
Rank 1
gabi asked on 06 Jul 2010, 08:41 AM

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 




1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 08 Jul 2010, 04:51 PM
Hello Gabor,

Thank you for sharing this solution. It concerns the culture issues of GridViewMaskBoxColumn which will be addressed in Q2 2010 of Telerik WinForms controls.

Regards,
Alexander
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
gabi
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or