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

FormatString RadGridView

3 Answers 2130 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Zerka
Top achievements
Rank 1
Zerka asked on 22 Nov 2010, 01:52 PM
Hi,

I am using RadGridView.  I need to format the column values, so it can display the values with no decimal points. And if the value of the column is 0 then it displays nothing. Can you please help me that what should be the value of FormatString property.

And also how can I format the values of SummaryRowBottom.

Any help would be appreciated.

Regards!

3 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 22 Nov 2010, 02:25 PM
Hello,

To add a summary row, please consider the following code
Dim summary As New GridViewSummaryRowItem() 
summary.Add(New GridViewSummaryItem("ColumnName", "{0} is the total of ColumnName", GridAggregateFunction.Sum)) 
Me.RadGridView1.SummaryRowsBottom.Add(summary) 

With formatting values in the way that you want, you need to consider if you are going to be using In grid editing. If not, then it is simply a case of defining a GridViewDecimalColumn and formatting the cells

Me.RadGridView1.Columns.Add(New GridViewDecimalColumn("MyValue"))

Dim rowInfo As GridViewRowInfo = Me.RadGridView1.Rows.AddNew()
rowInfo.Cells(0).Value = "2.31"
rowInfo.Cells(0).Value = "3.39"

Use CellFormatting event
Private Sub RadGridView1_CellFormatting(ByVal sender As System.Object, _
    ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
    If TypeOf e.CellElement.RowElement.RowInfo Is GridViewDataRowInfo Then
        If e.CellElement.RowElement.RowInfo.Cells("myValue").Value IsNot Nothing Then
            If e.CellElement.ColumnIndex = Me.RadGridView1.Columns("MyValue").Index Then
                e.CellElement.Value = e.CellElement.Value.ToString().Replace(".", "")
                If e.CellElement.Value.ToString() = "0" Then e.CellElement.Visibility = ElementVisibility.Hidden
            End If
        End If
    End If
End Sub

However, if you are using In grid editing, then the editor will now assume that 2.31 is 231.00. If you are not using this feature, then this shouldn't be an issue.

Let me know if you have further questions
Richard
0
Accepted
Zerka
Top achievements
Rank 1
answered on 22 Nov 2010, 04:06 PM
Hi

Thank you very much for your help. Actually I solved my problem in this way:

Format String for the column.

 

grdColumnDecimal.DecimalPlaces = 0;
  
grdColumnDecimal.DataEditFormatString = "{0:N0}"
  
grdColumnDecimal.FormatString = "{0:###,###}";

Format String for SummaryRowButton

GridViewSummaryRowItem item1 = new GridViewSummaryRowItem();
              
item1.Add(new GridViewSummaryItem("Total", "{0:###,###}",GridAggregateFunction.Sum));
  
grdRamme.SummaryRowsBottom.Add(item1);

Regards

 

0
Richard Slade
Top achievements
Rank 2
answered on 22 Nov 2010, 04:10 PM
Hello Michael,

I'm glad you've solved your issue. Actually, I think your way is preferable.
Best regards,
Richard
Tags
GridView
Asked by
Zerka
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Zerka
Top achievements
Rank 1
Share this question
or