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

Grid CellFormatting

5 Answers 243 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 27 Sep 2007, 08:56 AM
Hi, Telerik team

I hereby drop an issue that need Telerik Team to help.
I have a coding to differentiate the format of a row with other row of a column

for example:
stock  FOCTYPE  FOC
A          FOC          1
B          AMT        $1

i am using vb

my coding are:
dim Cols as GridViewDataColumn

the below coding is placed into CellFormating event of the Grid

if e.CellElement.ColumnInfo.UniqueName = "FOC" then
    TheType = e.CellElement.Value
    if TheType = "AMT" then
        Cols = new GridViewDataColumn("FOC")
        Cols.DataTextFormatString = "{0:c}"
    end if
end if

My question: Are the listed coding correct? because i never get the result i expected. The format for FOCTYPE = "AMT" still 1 instead of $1

Telerik Team's help is appreciated

Thanks in advance


5 Answers, 1 is accepted

Sort by
0
Erik
Top achievements
Rank 1
answered on 03 Oct 2007, 10:18 AM
So,

Any solution for this?
0
Tobin
Top achievements
Rank 1
answered on 05 Oct 2007, 08:40 AM
Hi Telerik, I am just using the telerik Q2, i found the same problem as erik does. Please help.

Help is deeply appreciated
0
Jack
Telerik team
answered on 08 Oct 2007, 02:08 PM
In this code just a new GridViewDataColumn is created, but it is never used. The right way to apply text formatting to GridCellElement is to set its FormatString property. Here is the code:

    Private Sub RadGridView1_CellFormatting(ByVal sender As System.ObjectByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting 
        Dim column As Telerik.WinControls.UI.GridViewDataColumn 
        If TypeOf e.CellElement.ColumnInfo Is Telerik.WinControls.UI.GridViewDataColumn Then 
            column = CType(e.CellElement.ColumnInfo, Telerik.WinControls.UI.GridViewDataColumn) 
            If column.DataField = "FOC" And e.CellElement.RowInfo.Cells("FOCTYPE").Value = "AMT" Then 
                column.DataTextFormatString = "{0:c}" 
                e.CellElement.FormatString = "{0:c}" 
            End If 
        End If 
    End Sub 

The format string does not work because probably you are using a GridViewTextBoxColumn and all values are converted to string. We will research this issue and will provide a solution in our next release, if needed.

 
Regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
piratenwichtl
Top achievements
Rank 1
answered on 10 Oct 2007, 02:52 AM
Hi,
i got a decimal value in my dataset and I try to display it with 3 digits..
like
#.##

I played around with the format quite a bit yet but I am not able to get it displayed as intended..... both with gridviewtextboxcolumn and decimalcolumn.
before I waste any more time, could you please give me a hint?

thanks in advance
t
0
Tobin
Top achievements
Rank 1
answered on 10 Oct 2007, 11:41 AM
This formatting issues has been discussed in this forum.

you can read this article http://www.telerik.com/community/forums/thread/b311D-hcabb.aspx

the formatting should be place into DataTextFormatString of the properties : MasterGridView --> column

Tags
GridView
Asked by
Erik
Top achievements
Rank 1
Answers by
Erik
Top achievements
Rank 1
Tobin
Top achievements
Rank 1
Jack
Telerik team
piratenwichtl
Top achievements
Rank 1
Share this question
or